473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:
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
1 7043
Dököll
2,364 Expert 2GB
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

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

Similar topics

1
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML:...
3
by: mike | last post by:
I am have a problem with my xslt test. <data> <struct_id>34</struct_id> <par_struct_id>0</par_struct_id> <chd_struct_id>41</chd_struct_id> </data> .. .. ..
4
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work)...
3
by: Scott M. Lyon | last post by:
I'm trying to figure out the best way (considering there could be instances where I get a lot of data in this XML, and I want to minimize any slowdowns) to extract the value of one particular node...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Kathy Burke | last post by:
Hi, I'm using Dim xDoc as XmlDocument Dim xElem As xmlElement = xDoc("xpath") I then assign a variable to a value from the result node: Dim r As String =...
1
by: Dica | last post by:
hi all first off, i'm not trying to cross post, but couldn't find this newsgroup earlier (got here from a recommendation on microsoft.public.vb, where i originally posted this question). ...
31
by: Peter Michaux | last post by:
Hi, I want to know the name of an object's constructor function as a string. Something like this <script type="text/javascript"> function Foo(){}; var a = new Foo(); alert('"' +...
4
by: daniel.bron | last post by:
Hello, Given a XML document, an XPath to a leaf node, and a string value, what is the briefest XSLT transform to change that node's value to the given string? The node is unique, unrepeated,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.