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.
LVL 1
Dustin StanleyEntrepreneurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
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"/>
Dustin StanleyEntrepreneurAuthor Commented:
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.
Gertone (Geert Bormans)Information ArchitectCommented:
you have this

<xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

Open in new window


this means that a e:Status element would be copied deep

If you have a template like this
<xsl:template match="e:Status">
...

Open in new window


It means you do something special with the e:Status element

However, you can be more precise
<xsl:template match="e:CheckoutStatus/e:Status">
...

Open in new window

and only do somethin special with the Status elements in a CheckoutStatus
But than the default processing (the deep copy) would work on the other Status elements

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dustin StanleyEntrepreneurAuthor Commented:
Perfect! Thank you for the Explanation.
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.