471,119 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 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 3449
Dormilich
8,656 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

Post your reply

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

Similar topics

reply views Thread by Sergio del Amo | last post: by
reply views Thread by M.sajjad | last post: by
5 posts views Thread by kebabkongen | last post: by
3 posts views Thread by shaun roe | last post: by
reply views Thread by Junior | last post: by

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.