Iam working on converting one of xml file to other form of xml using XSLT.
As part of this, I need to count the no. of "component" nodes in the xml file given below.
If there is only one "component" node,i have to assign the value of this node to "component" node in my output.xml file.
If there are more than one "component" nodes in my input xml file, then i should take the first "component" alphabetically that does not start with a space.
XML File:
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8" ?>
- <!-- RSS generated by JIRA 91 at Thu Sep 11 06:23:06 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-8214] Add Consistent Support for putting event labels (not tags) in between %% and $$ in Correlation Actions and Menu Configuration</title>
- <link>http://bugs.esecurity.net:8090/browse/SEN-8214</link>
- <description><![CDATA[Add support for putting labels between $xxx$ and %xxx%. When the strings are saved to the DB, replace the labels with the tags. Make sure this is done consistently between the Menu Configuration and Correlation Actions.]]></description>
- <environment><![CDATA[]]></environment>
- <key id="86829">SEN-8214</key>
- <summary>Add Consistent Support for putting event labels (not tags) in between %% and $$ in Correlation Actions and Menu Configuration</summary>
- <type id="4">Enhancement</type>
- <priority id="4">Minor</priority>
- <status id="6">Closed</status>
- <resolution id="1">Fixed</resolution>
- <assignee username="michael.cooper">Michael Cooper</assignee>
- <reporter username="john.gassner">John Gassner</reporter>
- <created>Thu, 19 Jun 2008 16:43:42 -0400 (EDT)</created>
- <updated>Fri, 27 Jun 2008 07:11:54 -0400 (EDT)</updated>
- <version>6.1.0.07</version>
- <fixVersion>6.1.0.09</fixVersion>
- <component>Menu Configuration</component>
- <component>Correlation</component>
- <due></due>
- <votes></votes>
- <comments>
- <comment author="hemendra.parmar" created="Thu, 26 Jun 2008 05:38:21 -0400 (EDT)" level="">Verified this issue using the latest code and found to be fixed. </comment>
- <comment author="vinutha.vasanthu" created="Fri, 27 Jun 2008 07:11:54 -0400 (EDT)" level="">Bug Verified on the Build(s):2008-06-20_SENTINEL_6.1.0.9
- Environment:SLES 10(32 bit) with Oracle10(32 bit)
- Status: Fixed
- Comments:
- Added labels with both $xx$ and %xx% in Menu configuration and correlation Action and the labels are replaced with tags which is as expected.Hence closed.</comment>
- </comments>
- <customfields>
- </customfields>
- </item>
- </channel>
- </rss>
Expand|Select|Wrap|Line Numbers
- <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">
- <bug>
- <xsl:variable name="ComponentCount" select="count(component)"/>
- <xsl:choose>
- <xsl:when test="$ComponentCount = '1'">
- <component><xsl:value-of select="component"/></component>
- </xsl:when>
- <xsl:otherwise>
- <xsl:for-each select="component">
- <xsl:sort select="."/>
- <xsl:if test=". != 'Documentation'">
- <component>
- <xsl:value-of select="."/>
- </component>
- </xsl:if>
- </xsl:for-each>
- </xsl:otherwise>
- </xsl:choose>
- </bug>
- </xsl:for-each>
- </bugzilla>
- </xsl:template>
- </xsl:stylesheet>
1) how to find whether an element value started with a space?
2) how to exit from the for-each when the first element with no space is found?
Any suggestions / help is highly urgent & appreciated.
Thanks,
Saritha