[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Embedding the XPath of an input Text Fragment in
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: 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.
|
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
|