Re: layout for entries in one group
Svante Schubert <[email protected]> Tue, 21 Feb 2006 11:18:58 +0100
| Newsgroups | gmane.comp.openoffice.devel.xml |
|---|---|
| Organization | StarOffice / Sun Microsystems, Inc. |
| Message-ID | <[email protected]> |
Hi Michael,
M. Niedermair wrote:
> Hi Svante,
>
>> you might do the following:
> [...]
> Sorry, but the solution dont work.
>
> with this example
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <a>
> <p style-name="Standard">Dies ist ein Text</p>
> <p style-name="Standard"/>
> <p style-name="listing">public class Test {</p>
> <p style-name="listing"> // ...</p>
> <p style-name="listing">}</p>
> <p style-name="Standard"/>
> <p style-name="Standard">noch eins</p>
> <p style-name="listing">public class Test {</p>
> <p style-name="listing"> // ...</p>
> <p style-name="listing">}</p>
> </a>
>
> i get the result with your xsl-file.
> <?xml version="1.0"?>
> <x>
> <p>Dies ist ein Text</p>
> <p></p>
> <listing>
> <p>public class Test {</p>
> <p> // ...</p>
> </listing>
> <p></p>
> <p>noch eins</p>
> </x>
>
Aye, apparently I hadn't this scenario in mind. I plea for insufficient
specification! ;-)
I didn't test sufficiently, so I forgot the 'position() = 1'
<xsl:if test="not(preceding-sibling::text:p[position() = 1 and
@text:style-name='listing'])">.
> but now i get a solution per email that works.
Very nice! Good to know that there are a few around, who are able to
program XSLT.
Only the one should sent it to everybody instead to the questioner
solely, so everybody can share the answer.
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes"/>
>
> <xsl:template match="p[@style-name='listing']">
> <xsl:if
> test="preceding-sibling::*[1][not(self::p)] or
> preceding-sibling::*[1][self::p[@style-name != current()/@style-name]]">
> <xsl:element name="listing">
> <xsl:apply-templates select="." mode="copy"/>
> </xsl:element>
> </xsl:if>
> </xsl:template>
>
> <xsl:template match="p[@style-name='listing']" mode="copy">
> <xsl:copy>
> <xsl:apply-templates/>
> </xsl:copy>
> <xsl:apply-templates
> select="following-sibling::*[1][self::p[@style-name =
> current()/@style-name]]"
> mode="copy"/>
> </xsl:template>
>
> <xsl:template match="@* | node()">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()"/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> the result is:
> <?xml version="1.0"?>
> <a>
> <p style-name="Standard">Dies ist ein Text</p>
> <p style-name="Standard"/>
> <listing>
> <p>public class Test {</p>
> <p> // ...</p>
> <p>}</p>
> </listing>
> <p style-name="Standard"/>
> <p style-name="Standard">noch eins</p>
> <listing>
> <p>public class Test {</p>
> <p> // ...</p>
> <p>}</p>
> </listing>
> </a>
>
> Thank you
> By
> Michael
cheers,
Svante