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

Aw:  Copy XPATH

Subject: Aw:  Copy XPATH
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Nov 2024 15:31:56 -0000
Aw:  Copy XPATH
XSLT/XPath 3 have a "path()" function. 

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=" <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 archiveEasyUnsubscribe (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.