Link to home
Start Free TrialLog in
Avatar of Dustin Stanley
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:
<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>

Open in new window



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>

Open in new window


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.
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

change
<xsl:template match="e:Status">
into
<xsl:template match="e:CheckoutStatus/e:Status">

and if you need to cut the other Status elements, add an empty template
<xsl:template match="e:Status"/>
Avatar of Dustin Stanley
Dustin Stanley

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
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect! Thank you for the Explanation.