473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to repeat some set of steps using xslt, as we do using functions in C or C++?

Hi,

As part of migrating bugs from JIRA to BugZilla, below is the requirement:

If there are multiple “version” tags in my input.xml file
For open bugs (Resolved,Reopened,Inprogress,NeedInfo) > create multiple bugs, one for each “version". “Fix version” will be empty.
For closed bugs > create multiple bugs, one for each “Fixed in” version. Use earliest “version" for all bugs.

I tried using the apply-template in the XSLT for the above requirement as shown below:

XSLT Code:

<xsl:if test="status = 'Open'">
<xsl:for-each select="/rss/channel/item/version">
<xsl:apply-templates select="/rss/channel/item">
<!--<xsl:with-param name="itemDetails" select="."/>-->
</xsl:apply-templates>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</bugzilla>
</xsl:template>
<xsl:template match="item">
<!--<xsl:param name="itemDetails"/>-->
<bug>
<version>
<xsl:value-of select="version" />
</version>
</bug>
</xsl:template>
</xsl:stylesheet>


XML Code:

<?xml version="1.0" encoding="UTF-8" ?>


<!-- RSS generated by JIRA 91 at Mon Sep 15 06:28:30 EDT 2008 -->

<rss version="0.92">
<channel>
<title>Sentinel Issue Tracking System</title>
<link>http://bugs.esecurity.net:8090</link>
<description>This file is an XML representation of an issue</description>
<language>en</language>
<item>
<title>[SEN-8448] CIDR-enabled dynamic lists</title>
<link>http://bugs.esecurity.net:8090/browse/SEN-8448</link>
<description><![CDATA[L-3 (Partner) requested to store in the dynamic list, a representation of a range of IP addresses against which we could correlate events. Given an entry of say, '192.168.0.0/24', we'd like to be able to ascertain whether or not a source or destination IP address falls in the range.
<br>
The inlist operator (Reference Guide, Chapter 6, Sentinel Correlation Engine RuleLG Language, page 6-3) would be wonderful, if we could extend to it some functionality - that is, if we could store an IP address range in CIDR notation, then use the 'match regex' or 'match subnet' operators to match a list item against an IP address present in an incoming event.
<br>

<br>
]]></description>
<environment><![CDATA[]]></environment>
<key id="87113">SEN-8448</key>
<summary>CIDR-enabled dynamic lists</summary>
<type id="4">Enhancement</type>
<priority id="5">Trivial</priority>
<status id="1">Open</status>
<resolution>Unresolved</resolution>
<assignee username="pattabiraman.srinivasan">Pattabiraman Srinivasan</assignee>
<reporter username="peng.liu">Peng Liu</reporter>
<created>Fri, 11 Jul 2008 14:07:41 -0400 (EDT)</created>
<updated>Fri, 11 Jul 2008 14:07:41 -0400 (EDT)</updated>
<version>6.1.0.17</version>
<version>6.0.0.0_SP2_Hotfix4</version>

<component>Correlation</component>
<component>Dynamic Lists</component>
<due></due>
<votes></votes>
<customfields>
</customfields>
</item>
</channel>
</rss>

With the above XSLT, i am getting two <bug></bug> tags with the same version ie, 6.1.0.17 instead of getting each with one version of input xml file.

Any help in this regard is highly appreciated.

Thanks,
Saritha
Sep 15 '08 #1
3 3677
Dormilich
8,658 Expert Mod 8TB
see line 15 of your xsl file:
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="version" />
you access all version child elements (the node-set resp), not a special one. If you want to make one <bug> per <version>, loop over <version>.

regards
Sep 15 '08 #2
jkmyoung
2,057 Expert 2GB
Agreed, you're looping on the version too early. If you wanted to do it that way, you'd have to pass in a parameter specifying which version you're pointing to.
But that's messy. Do it the other way instead.

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="status = 'Open'">
  2.   <!-- removed for-each>
  3.     <xsl:apply-templates select="/rss/channel/item"/>
  4. </xsl:if>
  5. </xsl:for-each>
  6. </bugzilla>
  7. </xsl:template>
  8.  
  9. <xsl:template match="item">
  10.   <xsl:for-each select="version">
  11.     <bug>
  12.       <version>
  13.         <xsl:value-of select="." />
  14.       </version>
  15.     </bug>
  16.   </xsl:for-each>
  17. </xsl:template>
  18. </xsl:stylesheet>
  19.  
Sep 16 '08 #3
Hi, Thanks for your reply. I tried passing a parameter to template and now iam able to repeat for each version.

Below is the xslt that worked fine:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<bugzilla version="3.0.4" urlbase="http://172.16.6.51/proj11/" maintainer="sunitha.akula@applabs.com" exporter="sunitha.akula@applabs.com">
<!--Repeat the below for all the bugs in the xml-->
<xsl:for-each select="/rss/channel/item">
<xsl:if test="status = 'Open'">
<xsl:for-each select="version">
<xsl:apply-templates select="ancestor::item">
<xsl:with-param name="AffectsVersion" select="."/>
<xsl:with-param name="FixVersion" select='string("")'/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</bugzilla>
</xsl:template>
<xsl:template match="item">
<xsl:param name="AffectsVersion"/>
<xsl:param name="FixVersion"/>
<bug>
<version>
<xsl:value-of select="$AffectsVersion" />
</version>
</bug>
</xsl:template>

</xsl:stylesheet>


Thanks,
Saritha

Agreed, you're looping on the version too early. If you wanted to do it that way, you'd have to pass in a parameter specifying which version you're pointing to.
But that's messy. Do it the other way instead.

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="status = 'Open'">
  2.   <!-- removed for-each>
  3.     <xsl:apply-templates select="/rss/channel/item"/>
  4. </xsl:if>
  5. </xsl:for-each>
  6. </bugzilla>
  7. </xsl:template>
  8.  
  9. <xsl:template match="item">
  10.   <xsl:for-each select="version">
  11.     <bug>
  12.       <version>
  13.         <xsl:value-of select="." />
  14.       </version>
  15.     </bug>
  16.   </xsl:for-each>
  17. </xsl:template>
  18. </xsl:stylesheet>
  19.  
Sep 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
0
by: M.sajjad | last post by:
Five Steps to Rapid Development with TierDeveloper 3.0 Unlock the power of rapid development when you use TierDeveloper from AlachiSoft in your N-Tier application development. Follow the steps...
2
by: sneill | last post by:
Hello all, In the August 2003 edition of "XML Journal" (see: http://xml.sys-con.com/read/40671.htm) Pietro Michelucci wrote an interesting article entitled "Object-Oriented XSLT". The article...
1
by: Peran | last post by:
If I create a simple xslt stylesheet I can quickly test this in VS2005 by pressing the "Show XSLT Output" button rather than running the whole solution. If I then create a xslt stylesheet with...
5
by: kebabkongen | last post by:
Hi, I have an XML source which gives me the start time (in the format hh:mi) of a program and the duration of the program (in minutes). With XSLT only, I would like to generate the time the next...
3
by: shaun roe | last post by:
mild rant follows Working now for a couple of years with xslt and now xslt 2.0, does anyone else get the impression that xslt 2.0 somehow missed the point? Yes its got a fancy new data model...
1
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
0
by: Junior | last post by:
I need to learn which pattern or some coding methodology I should use to repeat all of the steps when using a Wizard control. Each iteration of the Wizard has 10 steps each of which collects data....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.