Jump to content

Selecting Subtag Based On Attribute Value


Aussie Mike
 Share

Recommended Posts

xml...<Cashflow> <principalExchange id="startExchange"> <adjustedPrincipalExchangeDate>2009-06-15</adjustedPrincipalExchangeDate> <principalExchangeAmount>-23000.00</principalExchangeAmount> </principalExchange> <principalExchange id="maturityExchange"> <adjustedPrincipalExchangeDate>2009-06-16</adjustedPrincipalExchangeDate> <principalExchangeAmount>25567.00</principalExchangeAmount> </principalExchange></Cashflow>Attempted code.....based on answer i got from a similar issue <maturity_amount> <xsl:value-of select="//principalExchange[@id=$maturityExchange]/principalExchangeAmount"/></maturity_amount>As you can likely see i am wanting to extract the specific amount for maturity.In general i have been having difficulty navigating with and around these <tag attribute="value"> need to understand how to handle the syntax with these betterCheers

Link to comment
Share on other sites

The example me and aalbetski gave you was supposed to be a starting point...I suppose the real problem is that you need to give each maturity_amount the corresponding principalExchangeAmount, and not that this doesn't output anything, correct?XPath syntax:

nodenameSelects all child nodes of the named node /Selects from the root node //Selects nodes in the document from the current node that match the selection no matter where they are .Selects the current node ..Selects the parent of the current node @Selects attributes
Purpose of xsl:for-each:
The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set
purpose of xsl:value-of
The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation
NOTE: xsl:value-of returns only the first results from the resulting node-set.With that in mind, here's an excersize for you:
<xsl:for-each select="	get all elements for which you want to create a maturity_amount element   "><maturity_amount> <xsl:value-of select="	select the one node you need the value of... keep in mind that "//" usually matches multiple nodes	"/></maturity_amount></xsl:for-each>

Edited by boen_robot
Link to comment
Share on other sites

Thanks. The answer from the other covered this. I was aware of the <xsl:for each> option, but need to output these in wildly different places in my xml with indiviual tags. So the single extraction method seems best.Apologies for being a pain, but i am 4 days into my xslt life. I seem to have also inherited an xml feed that is incorporating every possible way of structuring the data. I've used nearly every command i've found. :-)Cheers for the help

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
 Share

×
×
  • Create New...