Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - is this possible with xlst? >Thread Next - Re: is this possible with xlst? Re: is this possible with xlst?To: NULL Date: 12/3/2007 9:42:00 PM
dave_kajinsky@h... wrote:
> Is it possible to write an xlst style sheet that takes both files as
> input and transforms them into:
> -- dave
text.txt:
This is just a simple text.
text.xml:
<!DOCTYPE text [<!ENTITY text SYSTEM "text.txt">]>
<text>&text;</text>
tokens.xml:
<tokens>
<token pos="6...7"/>
<token pos="14...14"/>
</tokens>
tokens.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:variable name="text" select="string(document('text.xml'))"/>
<xsl:template match="tokens">
<transformed_tokens>
<xsl:apply-templates/>
</transformed_tokens>
</xsl:template>
<xsl:template match="token">
<xsl:variable name="a" select="number(substring-before(@pos,'...'))"/>
<xsl:variable name="b" select="number(substring-after(@pos,'...'))"/>
<transformed_tokens text="{substring($text,$a,1+ $b - $a)}"/>
</xsl:template>
</xsl:stylesheet>
produces:
$ saxon tokens.xml tokens.xsl
<?xml version="1.0" encoding="utf-8"?>
<transformed_tokens>
<transformed_tokens text="is"/>
<transformed_tokens text="a"/>
</transformed_tokens>
Although I'd agree with Joseph that if your actual requirements are
anything much mre complicated than this, XSLT 1 isn't really the
language of choice. (XSLT2 may be, or not depending...)
--
http://dpcarlisle.blogspot.com
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
