How to test if node name matches given string value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redgrL86
    New Member
    • Jun 2007
    • 7

    How to test if node name matches given string value

    Hi,
    I am trying to figure out how to see if any of a given set of childnodes equals a given string. For example, in the XML and XSL code below, I want the text in the "xsl:when" statement to output when any of the childnodes of <FormulaValue > equal the string "Value". How can I do this?? I am trying to use XPath code but I can't get it to work.
    Thank you!!
    Christine

    XSL code:
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="/">
          <html>
             <body>
             <xsl:for-each select="RecipeElement/Steps/Step/FormulaValue">
             <xsl:choose>
             <xsl:when test="name(child::node()[3])=Value">
                     <d>Value is present</d>
             </xsl:when>
             </xsl:choose>
             </xsl:for-each>
             </body>
          </html>
       </xsl:template>
    </xsl:stylesheet>
    XML code:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="stylesheet13.xsl"?>
    <RecipeElement>
    <RecipeElementID>UFDF_CLEANING</RecipeElementID>
    	<Steps>
    		<InitialStep XPos="700" YPos="100">
    			<Name>INITIALSTEP:1</Name>
    		</InitialStep>
    		<TerminalStep XPos="800" YPos="1098">
    			<Name>TERMINALSTEP:1</Name>
    		</TerminalStep>
    		
    	<Step XPos="600" YPos="598" AcquireUnit="true">
    			<Name>UFDF_CLEANING:1</Name>
    			<StepRecipeID>UFDF_CLEANING</StepRecipeID>
    			<UnitAlias>UFDF_CLEANING:1</UnitAlias>
    		<FormulaValue>
    			<Name>PUMP_SPEED</Name>
    			<Display>false</Display>
    			<Value />
    			<Real>5</Real>
    			<EngineeringUnits />
    		</FormulaValue>
    	</Step>
    	</Steps>
    </RecipeElement>
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by redgrL86
    Hi,
    I am trying to figure out how to see if any of a given set of childnodes equals a given string. For example, in the XML and XSL code below, I want the text in the "xsl:when" statement to output when any of the childnodes of <FormulaValue > equal the string "Value". How can I do this?? I am trying to use XPath code but I can't get it to work.
    Thank you!!
    Christine

    XSL code:
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="/">
          <html>
             <body>
             <xsl:for-each select="RecipeElement/Steps/Step/FormulaValue">
             <xsl:choose>
             <xsl:when test="name(child::node()[3])=Value">
                     <d>Value is present</d>
             </xsl:when>
             </xsl:choose>
             </xsl:for-each>
             </body>
          </html>
       </xsl:template>
    </xsl:stylesheet>
    XML code:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="stylesheet13.xsl"?>
    <RecipeElement>
    <RecipeElementID>UFDF_CLEANING</RecipeElementID>
    	<Steps>
    		<InitialStep XPos="700" YPos="100">
    			<Name>INITIALSTEP:1</Name>
    		</InitialStep>
    		<TerminalStep XPos="800" YPos="1098">
    			<Name>TERMINALSTEP:1</Name>
    		</TerminalStep>
    		
    	<Step XPos="600" YPos="598" AcquireUnit="true">
    			<Name>UFDF_CLEANING:1</Name>
    			<StepRecipeID>UFDF_CLEANING</StepRecipeID>
    			<UnitAlias>UFDF_CLEANING:1</UnitAlias>
    		<FormulaValue>
    			<Name>PUMP_SPEED</Name>
    			<Display>false</Display>
    			<Value />
    			<Real>5</Real>
    			<EngineeringUnits />
    		</FormulaValue>
    	</Step>
    	</Steps>
    </RecipeElement>
    Hello, Christine!

    I am going to refer you to a wonderful link for the time being, see what you can pull up, find examples there:

    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
    Last edited by Dököll; Jun 26 '07, 01:52 AM. Reason: URL Tag

    Comment

    Working...