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(_dot_)nordgren(_at_)comhem(_dot_)se]
Sent: Wednesday, June 11, 2008 4:41 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_dot_)nordgren(_at_)comhem(_dot_)se
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
This message is private and confidential. If you have received it in error,
please notify the sender and remove it from your system.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--