By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

How to test if node name matches given string value

P: 7
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:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.    <xsl:template match="/">
  4.       <html>
  5.          <body>
  6.          <xsl:for-each select="RecipeElement/Steps/Step/FormulaValue">
  7.          <xsl:choose>
  8.          <xsl:when test="name(child::node()[3])=Value">
  9.                  <d>Value is present</d>
  10.          </xsl:when>
  11.          </xsl:choose>
  12.          </xsl:for-each>
  13.          </body>
  14.       </html>
  15.    </xsl:template>
  16. </xsl:stylesheet>
  17.  
XML code:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="stylesheet13.xsl"?>
  3. <RecipeElement>
  4. <RecipeElementID>UFDF_CLEANING</RecipeElementID>
  5.     <Steps>
  6.         <InitialStep XPos="700" YPos="100">
  7.             <Name>INITIALSTEP:1</Name>
  8.         </InitialStep>
  9.         <TerminalStep XPos="800" YPos="1098">
  10.             <Name>TERMINALSTEP:1</Name>
  11.         </TerminalStep>
  12.  
  13.     <Step XPos="600" YPos="598" AcquireUnit="true">
  14.             <Name>UFDF_CLEANING:1</Name>
  15.             <StepRecipeID>UFDF_CLEANING</StepRecipeID>
  16.             <UnitAlias>UFDF_CLEANING:1</UnitAlias>
  17.         <FormulaValue>
  18.             <Name>PUMP_SPEED</Name>
  19.             <Display>false</Display>
  20.             <Value />
  21.             <Real>5</Real>
  22.             <EngineeringUnits />
  23.         </FormulaValue>
  24.     </Step>
  25.     </Steps>
  26. </RecipeElement>
  27.  
Jun 25 '07 #1
Share this Question
Share on Google+
1 Reply


Dököll
Expert 100+
P: 2,364
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:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.    <xsl:template match="/">
  4.       <html>
  5.          <body>
  6.          <xsl:for-each select="RecipeElement/Steps/Step/FormulaValue">
  7.          <xsl:choose>
  8.          <xsl:when test="name(child::node()[3])=Value">
  9.                  <d>Value is present</d>
  10.          </xsl:when>
  11.          </xsl:choose>
  12.          </xsl:for-each>
  13.          </body>
  14.       </html>
  15.    </xsl:template>
  16. </xsl:stylesheet>
  17.  
XML code:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="stylesheet13.xsl"?>
  3. <RecipeElement>
  4. <RecipeElementID>UFDF_CLEANING</RecipeElementID>
  5.     <Steps>
  6.         <InitialStep XPos="700" YPos="100">
  7.             <Name>INITIALSTEP:1</Name>
  8.         </InitialStep>
  9.         <TerminalStep XPos="800" YPos="1098">
  10.             <Name>TERMINALSTEP:1</Name>
  11.         </TerminalStep>
  12.  
  13.     <Step XPos="600" YPos="598" AcquireUnit="true">
  14.             <Name>UFDF_CLEANING:1</Name>
  15.             <StepRecipeID>UFDF_CLEANING</StepRecipeID>
  16.             <UnitAlias>UFDF_CLEANING:1</UnitAlias>
  17.         <FormulaValue>
  18.             <Name>PUMP_SPEED</Name>
  19.             <Display>false</Display>
  20.             <Value />
  21.             <Real>5</Real>
  22.             <EngineeringUnits />
  23.         </FormulaValue>
  24.     </Step>
  25.     </Steps>
  26. </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:

http://www.w3schools.com/default.asp
Jun 26 '07 #2

Post your reply

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