wolfie78uk
Programmer
Hi,
Imagine that I have the following XML document:
<article>
<heading level="1">Heading1</heading>
<heading level="2">Sub1</heading>
<paragraph>1st <bold>block</bold> of info</paragraph>
<heading level="1">Heading2</heading>
<heading level="2">Sub2</heading>
<paragraph>2nd <italic>block</italic> of info</paragraph>
<heading level="1">Heading3</heading>
<heading level="2">Sub3</heading>
<paragraph>3rd <strong>block</strong> of info</paragraph>
</article>
and I want to transform it into :
<article>
<section>
<heading>Heading1</heading>
<sub-heading>Sub1</sub-heading>
<paragraph>1st <bold>block</bold> of info</paragraph>
</section>
<section>
<heading>Heading2</heading>
<sub-heading>Sub2</sub-heading>
<paragraph>2nd <italic>block</italic> of info</paragraph>
</section>
<section>
<heading>Heading3</heading>
<sub-heading>Sub3</sub-heading>
<paragraph>3rd <strong>block</strong> of info</paragraph>
</section>
</article>
I am using the following XSL :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/article">
<article>
<xsl:apply-templates select="heading" />
</article>
</xsl:template>
<xsl:template match="heading">
<xsl:choose select=".">
<xsl:when test ="@level < 2">
<xsl:element name="section">
<xsl:element name="heading">
<xsl:value-of select="." />
</xsl:element>
<xsl:apply-templates select="following-sibling::*" />
</xsl:element>
</xsl:when>
<xsl
therwise>
<xsl:element name="sub-heading">
<xsl:value-of select="." />
</xsl:element>
</xsl
therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Unfortunately, it is not producing the desired result because I need it to stop at each "heading".
Does anyone have any ideas about how I can achieve my goal (without resorting to writing parsing code).
Thanks,
Simon
Imagine that I have the following XML document:
<article>
<heading level="1">Heading1</heading>
<heading level="2">Sub1</heading>
<paragraph>1st <bold>block</bold> of info</paragraph>
<heading level="1">Heading2</heading>
<heading level="2">Sub2</heading>
<paragraph>2nd <italic>block</italic> of info</paragraph>
<heading level="1">Heading3</heading>
<heading level="2">Sub3</heading>
<paragraph>3rd <strong>block</strong> of info</paragraph>
</article>
and I want to transform it into :
<article>
<section>
<heading>Heading1</heading>
<sub-heading>Sub1</sub-heading>
<paragraph>1st <bold>block</bold> of info</paragraph>
</section>
<section>
<heading>Heading2</heading>
<sub-heading>Sub2</sub-heading>
<paragraph>2nd <italic>block</italic> of info</paragraph>
</section>
<section>
<heading>Heading3</heading>
<sub-heading>Sub3</sub-heading>
<paragraph>3rd <strong>block</strong> of info</paragraph>
</section>
</article>
I am using the following XSL :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/article">
<article>
<xsl:apply-templates select="heading" />
</article>
</xsl:template>
<xsl:template match="heading">
<xsl:choose select=".">
<xsl:when test ="@level < 2">
<xsl:element name="section">
<xsl:element name="heading">
<xsl:value-of select="." />
</xsl:element>
<xsl:apply-templates select="following-sibling::*" />
</xsl:element>
</xsl:when>
<xsl
<xsl:element name="sub-heading">
<xsl:value-of select="." />
</xsl:element>
</xsl
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Unfortunately, it is not producing the desired result because I need it to stop at each "heading".
Does anyone have any ideas about how I can achieve my goal (without resorting to writing parsing code).
Thanks,
Simon