[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Dear XSL experts,
I am trying to write a WordML to DocBook transformation. Everything works fine but I cannot instantiate the templates below. Hope that anyone can help me.
The input files looks like the following:
<?xml version="1.0" encoding="UTF-8"?>
<w:body
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2">
<w:p wsp:rsidP="00A161FC" wsp:rsidR="00A161FC" wsp:rsidRDefault="00882C04">
<w:pPr>
<w:pStyle w:val="heading1"/>
</w:pPr>
<w:r>
<w:t>1. </w:t>
</w:r>
<w:r wsp:rsidR="00A161FC">
<w:t>Eine Cberschrift Ebene 1</w:t>
</w:r>
<w:r wsp:rsidR="00076292">
<w:t> (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="007C4D27" wsp:rsidR="007C4D27" wsp:rsidRDefault="007C4D27" wsp:rsidRPr="007C4D27">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r>
<w:t>Ein Absatz. Ein Absatz. Ein Absatz.</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00176E25" wsp:rsidR="00176E25" wsp:rsidRDefault="00882C04">
<w:pPr>
<w:pStyle w:val="heading2"/>
</w:pPr>
<w:r>
<w:t>1.1 </w:t>
</w:r>
<w:r wsp:rsidR="00176E25">
<w:t>Cberschrift Ebene 2 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="005B5D4F" wsp:rsidR="005B5D4F" wsp:rsidRDefault="005B5D4F">
<w:pPr>
<w:pStyle w:val="heading3"/>
</w:pPr>
<w:r>
<w:t>1.1.1 Cberschrift Ebene 3 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00933AB1" wsp:rsidR="00933AB1" wsp:rsidRDefault="00933AB1" wsp:rsidRPr="00933AB1">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r wsp:rsidRPr="00933AB1">
<w:t>Ein Absatz (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00933AB1" wsp:rsidR="003E1625" wsp:rsidRDefault="003E1625" wsp:rsidRPr="003E1625">
<w:pPr>
<w:pStyle w:val="heading3"/>
</w:pPr>
<w:r>
<w:t>1.1.2</w:t>
</w:r>
<w:r wsp:rsidRPr="003E1625">
<w:t> Cberschrift Ebene 3 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00A161FC" wsp:rsidR="00A161FC" wsp:rsidRDefault="00A161FC">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r>
<w:t>Ein </w:t>
</w:r>
<w:r wsp:rsidRPr="00273261">
<w:rPr>
<w:rStyle w:val="emphasis1"/>
</w:rPr>
<w:t>Absatz</w:t>
</w:r>
<w:r wsp:rsidR="00076292">
<w:t> (K1)</w:t>
</w:r>
</w:p>
</w:body>
My xsl file:
<xsl:template name="chapter">
<xsl:param name="level" select="1"/>
<xsl:param name="nodes" select="*"/>
<xsl:for-each-group select="$nodes"
group-starting-with="*[descendant-or-self::*[@w:val=concat('heading',$level)]]">
<xsl:choose>
<xsl:when test="current-group()[descendant-or-self::*[@w:val=concat('heading',$level)]]">
<xsl:element name="sect{$level}">
<xsl:apply-templates select="node()"/>
<xsl:choose>
<xsl:when test="not(current-group()[position()!=1])">
<xsl:for-each-group select="current-group()[position()!=1]"
group-starting-with="*[descendant-or-self::*[@w:val=starts-with(.,'heading')]]">
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="chapter">
<xsl:with-param name="level" select="$level+1"/>
<xsl:with-param name="nodes" select="current-group()"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
And the output should look like the following;
[xsl] wordML to docbook -- please help
Subject: [xsl] wordML to docbook -- please help From: Andreas Peter <info@xxxxxxxxxx> Date: Mon, 30 Nov 2009 20:58:55 +0100 |
Dear XSL experts,
I am trying to write a WordML to DocBook transformation. Everything works fine but I cannot instantiate the templates below. Hope that anyone can help me.
The input files looks like the following:
<?xml version="1.0" encoding="UTF-8"?>
<w:body
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2">
<w:p wsp:rsidP="00A161FC" wsp:rsidR="00A161FC" wsp:rsidRDefault="00882C04">
<w:pPr>
<w:pStyle w:val="heading1"/>
</w:pPr>
<w:r>
<w:t>1. </w:t>
</w:r>
<w:r wsp:rsidR="00A161FC">
<w:t>Eine Cberschrift Ebene 1</w:t>
</w:r>
<w:r wsp:rsidR="00076292">
<w:t> (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="007C4D27" wsp:rsidR="007C4D27" wsp:rsidRDefault="007C4D27" wsp:rsidRPr="007C4D27">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r>
<w:t>Ein Absatz. Ein Absatz. Ein Absatz.</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00176E25" wsp:rsidR="00176E25" wsp:rsidRDefault="00882C04">
<w:pPr>
<w:pStyle w:val="heading2"/>
</w:pPr>
<w:r>
<w:t>1.1 </w:t>
</w:r>
<w:r wsp:rsidR="00176E25">
<w:t>Cberschrift Ebene 2 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="005B5D4F" wsp:rsidR="005B5D4F" wsp:rsidRDefault="005B5D4F">
<w:pPr>
<w:pStyle w:val="heading3"/>
</w:pPr>
<w:r>
<w:t>1.1.1 Cberschrift Ebene 3 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00933AB1" wsp:rsidR="00933AB1" wsp:rsidRDefault="00933AB1" wsp:rsidRPr="00933AB1">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r wsp:rsidRPr="00933AB1">
<w:t>Ein Absatz (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00933AB1" wsp:rsidR="003E1625" wsp:rsidRDefault="003E1625" wsp:rsidRPr="003E1625">
<w:pPr>
<w:pStyle w:val="heading3"/>
</w:pPr>
<w:r>
<w:t>1.1.2</w:t>
</w:r>
<w:r wsp:rsidRPr="003E1625">
<w:t> Cberschrift Ebene 3 (K1)</w:t>
</w:r>
</w:p>
<w:p wsp:rsidP="00A161FC" wsp:rsidR="00A161FC" wsp:rsidRDefault="00A161FC">
<w:pPr>
<w:pStyle w:val="paragraph"/>
</w:pPr>
<w:r>
<w:t>Ein </w:t>
</w:r>
<w:r wsp:rsidRPr="00273261">
<w:rPr>
<w:rStyle w:val="emphasis1"/>
</w:rPr>
<w:t>Absatz</w:t>
</w:r>
<w:r wsp:rsidR="00076292">
<w:t> (K1)</w:t>
</w:r>
</w:p>
</w:body>
My xsl file:
<xsl:template match="w:body"> <chapter> <xsl:call-template name="chapter"/> </chapter> </xsl:template>
<xsl:template name="chapter">
<xsl:param name="level" select="1"/>
<xsl:param name="nodes" select="*"/>
<xsl:for-each-group select="$nodes"
group-starting-with="*[descendant-or-self::*[@w:val=concat('heading',$level)]]">
<xsl:choose>
<xsl:when test="current-group()[descendant-or-self::*[@w:val=concat('heading',$level)]]">
<xsl:element name="sect{$level}">
<xsl:apply-templates select="node()"/>
<xsl:choose>
<xsl:when test="not(current-group()[position()!=1])">
<xsl:for-each-group select="current-group()[position()!=1]"
group-starting-with="*[descendant-or-self::*[@w:val=starts-with(.,'heading')]]">
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="chapter">
<xsl:with-param name="level" select="$level+1"/>
<xsl:with-param name="nodes" select="current-group()"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<!-- These templates are not instantiate --> <xsl:template match="w:p[descendant-or-self::*[@w:val='paragraph']]"> <para> <xsl:apply-templates/> </para> </xsl:template>
<xsl:template match="w:p[descendant-or-self::*[@w:val='heading1']]"> <title> <xsl:apply-templates/> </title> </xsl:template>
<xsl:template match="w:p[descendant-or-self::*[@w:val='heading2']]"> <title> <xsl:apply-templates/> </title> </xsl:template>
<xsl:template match="w:p[descendant-or-self::*[@w:val='heading3']]"> <title> <xsl:apply-templates/> </title> </xsl:template>
And the output should look like the following;
<?xml version="1.0" encoding="UTF-16"?> <book> <chapter> <sect1> <title>1. Eine Cberschrift Ebene 1 (K1)</title> <para>Ein Absatz. Ein Absatz. Ein Absatz.</para> <sect2> <title>1.1 Cberschrift Ebene 2 (K1)</title> <sect3> <title>1.1.1 Cberschrift Ebene 3 (K1)</title> <para>Ein Absatz (K1)</para> </sect3> <sect3> <title>1.1.2 Cberschrift Ebene 3 (K1)</title> <para>Ein <emphasis>Absatz</emphasis> (K1)</para> </sect3> </sect2> </sect1> </chapter> </book>
regards Andreas
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] reading files from direct, Mike Odling-Smee | Thread | [xsl] counting nodes before a certa, a kusa |
RE: [xsl] xslt:number numeration st, Michael Kay | Date | [xsl] counting nodes before a certa, a kusa |
Month |