CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: xsl condition

  1. #1
    Join Date
    Jan 2003
    Posts
    615

    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

  2. #2
    Join Date
    Dec 2001
    Location
    UK
    Posts
    308

    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!"

  3. #3
    Join Date
    Jan 2003
    Posts
    615

    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

  4. #4
    Join Date
    Dec 2001
    Location
    UK
    Posts
    308

    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 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
  •  





Click Here to Expand Forum to Full Width

Featured