[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Copy XPATH
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|