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:styleshee t version="1.0"
xmlns:xsl="htt p://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kNonEqFol low" match="paragrap h"
use="generat e-id(following-sibling::paragr aph[style != current()/style])"/>
<xsl:templat e match="document ">
<parsed>
<xsl:apply-templates select="paragra ph[not(preceding-sibling::paragr aph)
or style != preceding-sibling::paragr aph[1]/style]"/>
</parsed>
</xsl:template>
<xsl:templat e match="paragrap h[style = 'listing']">
<!-- find the first following with a different <style> -->
<xsl:variable name="non-eq"
select="genera te-id(following-sibling::paragr aph[style !=
current()/style])"/>
<list>
<xsl:for-each select=". | key('kNonEqFoll ow',$non-eq)">
<item>
<xsl:value-of select="text"/>
</item>
</xsl:for-each>
</list>
</xsl:template>
<xsl:templat e match="paragrap h[style = 'text']">
<!-- find the first following with a different <style> -->
<xsl:variable name="non-eq"
select="genera te-id(following-sibling::paragr aph[style !=
current()/style])"/>
<xsl:copy-of select="(. | key('kNonEqFoll ow',$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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="noneq" match="paragrap h"
use="generate-id(following-sibling::paragr aph[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="paragra ph[not(preceding-sibling::paragr aph)
or inner/style != preceding-sibling::paragr aph[1]/inner/style]"/>
<xsl:apply-templates select="$select ion"/>
</group>
</xsl:template>
<!-- -->
<xsl:template match="paragrap h[inner[style='Listing']]">
<xsl:variable name="non-eq"
select="generat e-id(following-sibling::paragr aph[inner[style !=
current()/inner/style]])"/>
<xsl:variable name="nodes" select="key('no neq',$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="paragrap h[inner[style='Paragrap hText']]">
<xsl:variable name="non-eq"
select="generat e-id(following-sibling::paragr aph/inner[style !=
current()/inner/style])"/>
<xsl:for-each select="(. | key('noneq',$no n-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>Paragrap hText</style>
</inner>
<rich>
<text>a text within a paragraph</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listin g</style>
</inner>
<rich>
<text>listing item #1</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listin g</style>
</inner>
<rich>
<text>listing item #2</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Paragrap hText</style>
</inner>
<rich>
<text>a text at the end of a paragraph</text>
</rich>
</paragraph>
</bording>
<bording>
<paragraph>
<inner>
<style>Paragrap hText</style>
</inner>
<rich>
<text>2 a text within a paragraph</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listin g</style>
</inner>
<rich>
<text>2 listing item #1</text>
</rich>
</paragraph>
<paragraph>
<inner>
<style>Listin g</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