Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: XSLT modifying an xml dom tree? >Thread Next - Re: XSLT modifying an xml dom tree? Re: XSLT modifying an xml dom tree?To: NULL Date: 8/1/2005 3:07:00 PM Tempore 15:35:06, die Monday 01 August 2005 AD, hinc in foro {comp.text.xml} scripsit Prashanth Ellina <prashanthellina@g...>:
> I find the XSLT programming model very alien and un-intuitive.
You'll be used to it in no time;) It's just another way of thinking.
> This is what I am looking to do
> ...
This a grouping problem, here's a solution with the Muenchian grouping technique, one of the most alien things for beginners:-)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="author" match="author" use="."/>
<xsl:variable name="allAuthors" select="//author[generate-id()=generate-id(key('author',.)[1])]"/>
<xsl:template match="booksinformation">
<xsl:copy>
<bookdata>
<xsl:apply-templates/>
</bookdata>
<authordata>
<xsl:for-each select="$allAuthors">
<author id="{position()}" name="{.}"/>
</xsl:for-each>
</authordata>
</xsl:copy>
</xsl:template>
<xsl:template match="book">
<xsl:variable name="author" select="author"/>
<xsl:copy>
<xsl:attribute name="author">
<xsl:for-each select="$allAuthors">
<xsl:if test=". = $author"><xsl:value-of select="position()"/></xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:copy-of select="title"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Deserta faciunt et innovationem appelant
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
