B
Buchleitner Martin
Hi!
I got another problem parsing my XML document:
<document>
<paragraph>
<style val=listing/>
<text>listing #1 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #1 text</text>
</paragraph>
<paragraph>
<style>text</style>
<text>some text between 2 listings</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
</document>
The output should look like:
<parsed>
<list>
<item>listing #1 text</item>
<item>listing #1 text</item>
<list>
<text>some text between 2 listings</text>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
</parsed>
My idea to get this result was:
<xsl:template match="text">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="paragaph">
<xsl:if text="style[@val='listing'>
<list>
<item><xsl:apply-templates select="text"></item>
<xsl:for-each
select="following-sibling:aragraph/style[@val='listing']">
<item><xsl:apply-templates select="text"></item>
</xsl:for-each>
</list>
</xsl:if>
</xsl:template>
<xsl:template match="document">
<xsl:apply-templates select="paragraph"/>
</xsl:template>
But i was wrong - i get a document like:
<parsed>
<list>
<item>listing #1 text</item>
<item>listing #1 text</item>
<list>
<list>
<item>listing #1 text</item>
<list>
<text>some text between 2 listings</text>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
<list>
<item>listing #2 text</item>
</list>
</parsed>
How may i change my XSL to remove the repeated entries?
Can i modify the position in the paragraph-template?
Any ideas?
TIA, Martin
I got another problem parsing my XML document:
<document>
<paragraph>
<style val=listing/>
<text>listing #1 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #1 text</text>
</paragraph>
<paragraph>
<style>text</style>
<text>some text between 2 listings</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
<paragraph>
<style val=listing/>
<text>listing #2 text</text>
</paragraph>
</document>
The output should look like:
<parsed>
<list>
<item>listing #1 text</item>
<item>listing #1 text</item>
<list>
<text>some text between 2 listings</text>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
</parsed>
My idea to get this result was:
<xsl:template match="text">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="paragaph">
<xsl:if text="style[@val='listing'>
<list>
<item><xsl:apply-templates select="text"></item>
<xsl:for-each
select="following-sibling:aragraph/style[@val='listing']">
<item><xsl:apply-templates select="text"></item>
</xsl:for-each>
</list>
</xsl:if>
</xsl:template>
<xsl:template match="document">
<xsl:apply-templates select="paragraph"/>
</xsl:template>
But i was wrong - i get a document like:
<parsed>
<list>
<item>listing #1 text</item>
<item>listing #1 text</item>
<list>
<list>
<item>listing #1 text</item>
<list>
<text>some text between 2 listings</text>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
<list>
<item>listing #2 text</item>
<item>listing #2 text</item>
<list>
<list>
<item>listing #2 text</item>
</list>
</parsed>
How may i change my XSL to remove the repeated entries?
Can i modify the position in the paragraph-template?
Any ideas?
TIA, Martin