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

Re: Copy XPATH

Subject: Re: Copy XPATH
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Nov 2024 15:55:17 -0000
Re:  Copy XPATH
As Martin Honnen noted, in XPath or XSLT ver 3+ one can use the standard
path() function - https://www.w3.org/TR/xpath-functions-31/#func-path

For a solution with XSLT 1.0 (or 2.0) see this Stack Overflow answer:
https://stackoverflow.com/a/4747858/36305

Thanks,
Dimitre

On Mon, Nov 11, 2024 at 7:28b/AM Byomokesh Sahoo sahoo.byomokesh@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
> Hi,
>
> I am trying to copy XPATH along with attributes value in an OUTPUT xml
> file.
>
> XML:
> <bb>
> <as id="ENCA" major.version="6" minor.version="0">
>     <tl>The Title</tl>
>     <b/>
>     <ts id="ENCA_GC">
>         <tl>TS Title text</tl>
>         <st jr="IB" id="EA_T1">
>             <tl>ST Title Text</tl>
>             <st.body>
>                 <pr>
>                     <sp>
>                         <sp.txt align="centre" cont="n">
>                             <emphasis type="bold"
> shading="nil">INTRODUCTION</emphasis>
>                         </sp.txt>
>                     </sp>
>                 </pr>
>             </st.body>
>         </st>
>     </ts>
> </as>
> </bb>
>
> Output Required
>
> <as title="The Title" xpath="bb/as[1]" id="ACLL.CA">
>         <ts title="TS Title text" xpath="bb/as[1]/ts[1]" id="ENCA_GC">
>             <st jr="IB" title="ST Title Text"
> xpath="/bb/as[1]/ts[1]/st[1]" id="EA_T1"/>
>             <st.body xpath="bb/as[1]/ts[1]/st[1]/st.body[1]">
>                 <pr xpath="bb/as[1]/ts[1]/st[1]/st.body[1]/pr[1]">
>                     <sp
> xpath="bb/as[1]/ts[1]/st[1]/st.body[1]/pr[1]/sp[1]"/>
>                     <sp.txt count="n"
> xpath="bb/as[1]/ts[1]/st[1]/st.body[1]/pr[1]/sp[1]/sp.txt[1]">
>                 </sp.txt>
>             </pr>
>         </st.body>
>     </ts>
> </as>
>
> XSL:
>
> <xsl:template match="as">
>         <xsl:element name="as">
>             <xsl:attribute name="title">
>                 <xsl:value-of select="title/node()"/>
>             </xsl:attribute>
>         <xsl:attribute name="xpath">
>             <xsl:value-of select ="local-name()"/>
>         </xsl:attribute>
>         </xsl:element>
>     </xsl:template>
>
>     <xsl:template match="ts">
>         <xsl:element name="ts">
>             <xsl:attribute name="title">
>                 <xsl:value-of select="title/node()"/>
>             </xsl:attribute>
>             <xsl:attribute name="xpath">
>                 <xsl:value-of select="fn:generateXPath(guidecard)"/>
>             </xsl:attribute>
>         </xsl:element>
>     </xsl:template>
>
>     <xsl:function name="fn:generateXPath" as="xs:string">
>         <xsl:param name="pNode" as="node()"/>
>         <xsl:for-each select="$pNode/ancestor::*">
>             <xsl:value-of select="name()" />
>         </xsl:for-each>
>     </xsl:function>
>
>     <xsl:template match="st.body" >
>         <st.body>
>         <xsl:value-of select="fn:generateXPath(st.body)"/>
>         </st.body>
>     </xsl:template>
>
> Please suggest.
>
> Thanks
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)

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.