Subject: RE: [xsl] Embedding the XPath of an input Text Fragment in output From: "Ryan Graham" <Ryan.Graham@xxxxxxxxxxx> Date: Wed, 11 Jun 2008 17:47:01 -0700 |
Here's a basic 1.0 solution that should return the xpath creation you describe. It operates on every text node, so you'll have to tweak it if you need to narrow the processing scope depending on your input document format. Depending on how you are processing your input files you can access the document's file name. (e.g. loading with document() function via input parameters). <xsl:template match="/"> <gcdocument> <xsl:apply-templates/> </gcdocument> </xsl:template> <xsl:template match="text()"> <xsl:variable name="ancestorPath"> <xsl:for-each select="ancestor::*"> <xsl:variable name="localName" select="name()"/> <xsl:value-of select="concat('/',name(),'[', count(preceding-sibling::*[name() = $localName]) + 1,']')"/> </xsl:for-each> </xsl:variable> <xsl:variable name="localPath" select="concat('/text()[',count(preceding-sibling::text()) + 1,']')"/> <textfragment> <xpath><xsl:value-of select="concat($ancestorPath, $localPath)"/></xpath> <Text><xsl:value-of select="."/></Text> </textfragment> </xsl:template> HTH, Ryan -----Original Message----- From: Tommy Nordgren [mailto:tommy.nordgren@xxxxxxxxx] Sent: Wednesday, June 11, 2008 4:41 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Embedding the XPath of an input Text Fragment in output I want to generate the following type of document. <gcdocument filename="..."> <textfragment> <xpath>The xpath of the first text fragment goes here</xpath> <Text>This is some natural language text that I want to grammar check.</text> </textfragment> <!-- as many textfragment tags as necessary to represent an input xml document --> </gcdocument> Is it possible to embed the xpath of text fragments this way. [The xpath from file filenmame] ------------------------------------- This sig is dedicated to the advancement of Nuclear Power Tommy Nordgren tommy.nordgren@xxxxxxxxx This message is private and confidential. If you have received it in error, please notify the sender and remove it from your system.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Embedding the XPath of an inp, Tommy Nordgren | Thread | RE: [xsl] Embedding the XPath of an, Wendell Piez |
Re: [xsl] Oracle XSLT 2.0 processor, Jim Melton | Date | [xsl] Simple Metrics Can't see how , Arthur Maloney |
Month |