March 28th, 2007, 06:26 AM
#1
xsl condition
Given this XML;
Code:
<Nodes>
<Node>
<Software id="A" version="1.2.3.4"/>
<Software id="B" version="2.2.3.4"/>
<Software id="C" version="3.2.3.4"/>
Trying to get version for Software with ID='a', doing this fails;
Code:
<xsl:for-each select="/Nodes/Node">
<xsl:value-of select="./Software[@id='A']/@version"/>
</xsl:for-each>
The two below work fine but are not specific enough (can fail if order is different)
Code:
<xsl:for-each select="/Nodes/Node">
<xsl:value-of select="./Software/@version"/>
</xsl:for-each>
//and
<xsl:for-each select="/Nodes/Node">
<xsl:value-of select="./Software[1]/@version"/>
</xsl:for-each>
Appreciate any input (apologise for any typo's - typed the example in by memory).
Before post , make an effort yourself, try
googling or
search here .
When posting , give a proper description of your problem, include code* and error messages.
*All code should include code tags
March 28th, 2007, 09:35 AM
#2
Re: xsl condition
this may not be the best solution.. but this will work....
Cheers
Venu
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="Nodes">
<NodeDetails xmlns="http://tempuri.org">
<xsl:for-each select="/Nodes/Node/Software">
<xsl:if test="@id='B'">
<ver> <xsl:value-of select="@version"/> </ver>
</xsl:if>
</xsl:for-each>
</NodeDetails>
</xsl:template>
</xsl:stylesheet>
Venu Bharadwaj
"Dream it. U can do it!"
March 29th, 2007, 05:00 AM
#3
Re: xsl condition
Thanks for the reply.
This didn't work, nothing appears inbetween <ver>.
Code:
<xsl:for-each select="/Software">
<xsl:if test="@id='B'">
<ver> <xsl:value-of select="@version"/></ver>
</xsl:if>
</xsl:for-each>
However this works but obviously prints both versions. Is there anything special regarding the equals operation?
Code:
<xsl:for-each select="/Software">
<xsl:if test="@id">
<ver> <xsl:value-of select="@version"/></ver>
</xsl:if>
</xsl:for-each>
Using Winxp sp2, .NET 1.1 and IIS 5.1
Before post , make an effort yourself, try
googling or
search here .
When posting , give a proper description of your problem, include code* and error messages.
*All code should include code tags
March 29th, 2007, 11:52 AM
#4
Re: xsl condition
surprisingly it is working on my machine ! .. i'm not sure why it is not working on your PC...
Here by i'm sending both XML and XSL file i used...
let me know error in this...
Cheer
Venu
Attached Files
Venu Bharadwaj
"Dream it. U can do it!"
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width