On Mon, 7 Jul 2003 11:49:24 +0100, "Marrow"
<marrow-NO-@-SPAM-marrowsoft.com> wrote:
Hi out there!
== XSL1 ================================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kNonEqFollow" match="paragraph"
use="generate-id(following-sibling::paragraph[style != current()/style])"/>
<xsl:template match="document">
<parsed>
<xsl:apply-templates select="paragraph[not(preceding-sibling::paragraph)
or style != preceding-sibling::paragraph[1]/style]"/>
</parsed>
</xsl:template>
<xsl:template match="paragraph[style = 'listing']">
<!-- find the first following with a different <style> -->
<xsl:variable name="non-eq"
select="generate-id(following-sibling::paragraph[style !=
current()/style])"/>
<list>
<xsl:for-each select=". | key('kNonEqFollow',$non-eq)">
<item>
<xsl:value-of select="text"/>
</item>
</xsl:for-each>
</list>
</xsl:template>
<xsl:template match="paragraph[style = 'text']">
<!-- find the first following with a different <style> -->
<xsl:variable name="non-eq"
select="generate-id(following-sibling::paragraph[style !=
current()/style])"/>
<xsl:copy-of select="(. | key('kNonEqFollow',$non-eq))/text"/>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 =========================================
However, if you are using MSXML 3.0 or MSXML 4.0 (pre SP2) then that
stylesheet will not work correctly due to a bug with current() in keys. An
alternative would be...
I am using Xalan-j so it should be ok or?
I adapted now this XSL1 to my needings:
=========XSL====================================== =======
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="noneq" match="paragraph"
use="generate-id(following-sibling::paragraph[inner[style !=
current()/inner/style]])"/>
<xsl:template match="document">
<parsed>
<xsl:apply-templates select="bording"/>
</parsed>
</xsl:template>
<xsl:template match="bording">
<group>
<xsl:variable name="selection"
select="paragraph[not(preceding-sibling::paragraph)
or inner/style != preceding-sibling::paragraph[1]/inner/style]"/>
<xsl:apply-templates select="$selection"/>
</group>
</xsl:template>
<!-- -->
<xsl:template match="paragraph[inner[style='Listing']]">
<xsl:variable name="non-eq"
select="generate-id(following-sibling::paragraph[inner[style !=
current()/inner/style]])"/>
<xsl:variable name="nodes" select="key('noneq',$non-eq)"/>
<list>
<xsl:for-each select=". | $nodes">
<item>
<xsl:value-of select="rich/text"/>
</item>
</xsl:for-each>
</list>
</xsl:template>
<!-- -->
<xsl:template match="paragraph[inner[style='ParagraphText']]">
<xsl:variable name="non-eq"
select="generate-id(following-sibling::paragraph/inner[style !=
current()/inner/style])"/>
<xsl:for-each select="(. | key('noneq',$non-eq))">
<absatz>
<xsl:value-of select="rich/text"/>
</absatz>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
=========end of XSL=======================================
the corresponding XML is
=========XML====================================== =======
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<bording>
<paragraph>
<inner>
<style>ParagraphText</style>
</inner>
<rich>
<text>a text within a paragraph</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listing</style>
</inner>
<rich>
<text>listing item #1</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listing</style>
</inner>
<rich>
<text>listing item #2</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>ParagraphText</style>
</inner>
<rich>
<text>a text at the end of a paragraph</text>
</rich>
</paragraph>
</bording>
<bording>
<paragraph>
<inner>
<style>ParagraphText</style>
</inner>
<rich>
<text>2 a text within a paragraph</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listing</style>
</inner>
<rich>
<text>2 listing item #1</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listing</style>
</inner>
<rich>
<text>2 listing item #2</text>
</rich>
</paragraph>
</bording>
</document>
=========end of XML=======================================
these two produce following output:
=========Output=================================== ==========
<?xml version="1.0" encoding="UTF-8"?>
<parsed>
<group>
<absatz>a text within a paragraph</absatz>
<list>
<item>listing item #1</item>
<item>listing item #2</item>
</list>
<absatz>a text at the end of a paragraph</absatz>
<absatz>2 listing item #1</absatz>
<absatz>2 listing item #2</absatz>
</group>
<group>
<absatz>2 a text within a paragraph</absatz>
<list>
<item>a text at the end of a paragraph</item>
<item>2 listing item #1</item>
<item>2 listing item #2</item>
</list>
</group>
</parsed>
=========end of Output=======================================
But i want an output like the following:
================================================== ========
<?xml version="1.0" encoding="UTF-8"?>
<parsed>
<group>
<absatz>a text within a paragraph</absatz>
<list>
<item>listing item #1</item>
<item>listing item #2</item>
</list>
<absatz>a text at the end of a paragraph</absatz>
</group>
<group>
<absatz>2 a text within a paragraph</absatz>
<list>
<item>2 listing item #1</item>
<item>2 listing item #2</item>
</list>
</group>
</parsed>
================================================== ========
How can i rewrite my matching key to work only with the paragraph tags
within the bording - element??
TIA, Martin