Dustin Stanley
asked on
How To Choose Which Elements To Alter In a XML with XSLT
Yesterday I learned how to alter a XML with XSLT using the following code:
But when I use the code such as:
It picks all the Elements with the name <Status>.
What if I only want it to choose the <Status> that is under the parent <CheckoutStatus>?
Thanks for the help.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e="urn:ebay:apis:eBLBaseComponents">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="e:Buyer">
<Buyer>
<OrderID><xsl:value-of select="ancestor::e:Order/e:OrderID"/></OrderID>
<xsl:apply-templates select="@*|node()"/>
</Buyer>
</xsl:template>
<xsl:template match="e:Item">
<Item>
<OrderID><xsl:value-of select="ancestor::e:Order/e:OrderID"/></OrderID>
<xsl:apply-templates select="@*|node()"/>
</Item>
</xsl:template>
</xsl:stylesheet>
But when I use the code such as:
</xsl:template>
<xsl:template match="e:Status">
<Status>
<OrderID><xsl:value-of select="ancestor::e:Order/e:OrderID"/></OrderID>
<xsl:apply-templates select="@*|node()"/>
</Status>
</xsl:template>
It picks all the Elements with the name <Status>.
What if I only want it to choose the <Status> that is under the parent <CheckoutStatus>?
Thanks for the help.
ASKER
and if you need to cut the other Status elements, add an empty template
<xsl:template match="e:Status"/>
What do you mean exactly by "and if you need to cut the other Status elements"?
Changing the path worked. Thank you for the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thank you for the Explanation.
welcome
<xsl:template match="e:Status">
into
<xsl:template match="e:CheckoutStatus/e:
and if you need to cut the other Status elements, add an empty template
<xsl:template match="e:Status"/>