[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Need XSLT help Please

Subject: Re: Need XSLT help Please
From: "David Rudel fwqhgads@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 Jul 2016 04:21:02 -0000
Re:  Need XSLT help Please
What you are looking to do can be prescribed as:

1. When you see a <PS> element, include a copy of the <ANUMBER>
element that is its ancestor.

2. Otherwise, keep everything the same.

Let's do number 2 first: the easy way to do this in xslt3 is with this
instruction:

<xsl:mode on-no-match="shallow-copy"/>

This says "unless I tell you otherwise, just make a copy of everything
you see." (Technically it says "anytime you hit a node that has no
prescribed instruction, copy the node and then process each of its
elements inside the copy you made.")

To do number 1 you want something like this:

<xsl:template match="PS">
    <xsl:copy>
<xsl:copy-of select="@*"/>
        <xsl:copy-of select="ancestor::ANUMBER[1]"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

This says "When you hit a PS mode, make a copy (including any
attributes), then embed a copy of the nearest ancestor ANUMBER mode
(the "[1]" says "the first one you see as you move up the chain of
ancestors).
Then the <xsl:apply-templates/> instruction tells the program to move
on processing all the children of the <PS> element.

So altogether I think this should work:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="PS">
    <xsl:copy>
<xsl:copy-of select="@*"/>
        <xsl:copy-of select="ancestor::ANUMBER"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>


On Thu, Jul 28, 2016 at 7:59 PM, Rahul Singh
rahulsinghindia15@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
>
> Hi,
>
> I am Begineer not much experience in XSL so that i have posted that question. I had tried lot but get fail. I need XSLT code for that sample input output:
>
> I tried much but fail. My question is put ANUMBER from AC with corresponding PS.
>
>
> Sample Input:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ACS>
>    <AC>
>       <ANUMBER>55555</ANUMBER>
>       <PSS>
>          <PS>
>             <S>NEF</S>
>             <C>63872R798</C>
>          </PS>
>       </PSS>
>    </AC>
>    <AC>
>       <ANUMBER>330448</ANUMBER>
>       <PSS>
>          <PS>
>             <S/>
>             <C>1060150</C>
>          </PS>
>          <PS>
>             <S/>
>             <C>1260150</C>
>          </PS>
>       </PSS>
>    </AC>
> </ACS>
>
>
>
>
> Sample OutPut:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ACS>
>    <AC>
>       <ANUMBER>55555</ANUMBER>
>       <PSS>
>          <PS>
>             <ANUMBER>55555</ANUMBER>
>             <S>NEF</S>
>             <C>63872R798</C>
>          </PS>
>       </PSS>
>    </AC>
>    <AC>
>       <ANUMBER>330448</ANUMBER>
>       <PSS>
>          <PS>
>             <ANUMBER>330448</ANUMBER>
>             <S/>
>             <C>1060150</C>
>          </PS>
>          <PS>
>             <ANUMBER>330448</ANUMBER>
>             <S/>
>             <C>1260150</C>
>          </PS>
>       </PSS>
>    </AC>
> </ACS>
>
> XSL-List info and archive
> EasyUnsubscribe (by email)




-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.