Subject: [xsl] problem with creating structure From: Andreas Peter <info@xxxxxxxxxx> Date: Sun, 11 Nov 2007 22:05:16 +0100 |
<Root> <Textabschnitt> <h1>Geistiger Volksbesitz der Kameruner im Blickfeld des Missionars</h1> <h2>EinfC<hrung </h2> <p>...</p> <p>...</p> <p>...</p> <p>...</p> <p>...</p> <h2>I.Teil: Der Mensch B ein Leib </h2> <h3>Allgemeines </h3> <p>...</p> <p>...</p> <p>...</p> <p>...</p> <p>...</p> </Textabschnitt> </Root>
<set> <book> <bookinfo/> <title/> <chapter> <title/> <para/> <sect1> <title/> <para/> </sect1> <sect2> <title/> <para/> </sect2> <sect3> <title/> <para/> </sect3> </chapter> </book> </set>
I want to insert an element <chapter> before the element <h2> but only for the first element <h2>. The second element <h2> should be transformed to <title>. And I need to output every <p> element according to its proir element until the next <h2>, <h3>, ... occures. I have the following XSL code which generates for every <h2> element an element <chapter>.
<xsl:template match="Root"> <xsl:element name="set"> <xsl:element name="book"> <xsl:element name="bookinfo"/> <xsl:element name="title"> <xsl:value-of select="/h1"/> </xsl:element> <xsl:apply-templates/> </xsl:element> </xsl:element> </xsl:template>
<xsl:template match="h2"> <xsl:for-each select="."> <xsl:if test="position() = 1"> <xsl:element name="chapter"> <xsl:element name="title"> <xsl:value-of select=".[position() = 1]"/> </xsl:element> </xsl:element> </xsl:if> <xsl:if test="position() != 1"> <xsl:element name="title"> <xsl:value-of select=".[position() != 1]"/> </xsl:element> </xsl:if> </xsl:for-each> <xsl:apply-templates/> </xsl:template>
<xsl:template match="h3"> <xsl:for-each select="."> <xsl:element name="sect1"> <xsl:element name="title"> <xsl:value-of select="."/> </xsl:element> </xsl:element> </xsl:for-each> <xsl:apply-templates/> </xsl:template>
<xsl:template match="h4"> <xsl:for-each select="."> <xsl:element name="sect2"> <xsl:element name="title"> <xsl:value-of select="."/> </xsl:element> <xsl:for-each select="Root/Textabschnitt/h4/p"> <xsl:element name="para"> <xsl:value-of select="p"/> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> <xsl:apply-templates/> </xsl:template>
Unfortunately I cannot see the problem. Any hint from the experts? I hope this is enough code.
Thanks so much, Andreas
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] translation() function?, Mukul Gandhi | Thread | Re: [xsl] problem with creating str, G. Ken Holman |
Re: [xsl] Wide Finder in XSLT --> d, M. David Peterson | Date | Re: [xsl] problem with creating str, G. Ken Holman |
Month |