Jump to content

How To Access Value Of A Node In A For-each When Multiple Same-named Children Exist


Recommended Posts

Hello.I have an XML file which eventually leads to something like this:

<function>  <parameter name="param1">Param1 description.</parameter>  <parameter name="param2">Param2 description here!</parameter>  <parameter name="param3">Param3 does something else, maybe...</parameter>  <returnValue>Returns true if Danny gets it right.</returnValue></function><function>  .. (similar) ..</function>

By iterating through each <parameter> in a for-each loop -- per function, which is in its own loop -- I am able to get any parameters the function may have, whether it be 0, 1, or 50 of 'em. My problem comes when I use the following XSLT code to get the values:

<xsl:for-each select="parameter">  <xsl:valueof select="@name"/>  <xsl:value-of select="../parameter"></xsl:for-each><xsl:value-of select="returns"/>

This is leading to no output of the <parameter> value itself. If you're using what I've posted, then I'm looking for "Param1 description", "Param2 description here!", etc. Instead, with the above XSLT file -- directed at "../parameter" after much trial and error -- I find myself just seeing:Param1 descriptionParam1 description... (continues for each <parameter> tag)How can I access the value of the node used in the for-each loop without referencing up such that I end up at the first node repeatedly, instead drawing the value of each node iterated through?

Edited by hyliandanny
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...