[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: group-starting-with drops child text nodes - work

Subject: Re: group-starting-with drops child text nodes - workaround?
From: tom schmitter <tshmit@xxxxxxxxx>
Date: Tue, 15 Jun 2010 17:23:50 -0700 (PDT)
Re:  group-starting-with drops child text nodes -  work
sorry.

<xsl:template match="section">
    <xsl:copy >
        <xsl:for-each-group select="*" group-starting-with="subtitle">
            <xsl:choose>
                <xsl:when test="name(current-group()[1]) != 'subtitle'">
                    <xsl:apply-templates select="."/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:element name="section">
                        <xsl:element name="h1">
                            <xsl:value-of select="."/>
                        </xsl:element>
                        <xsl:apply-templates select="current-group()[position() != 1]"/>
                    </xsl:element>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>


The idea is convert a <subtitle> to a <section> and drop the value of the subtitle into a following <h1>. eg

Input:

<test>
    <section>
    preamble
        <subtitle>section 1</subtitle>
            text
            <b>bolded text</b>
            more text
        <subtitle>section 2</subtitle>
    yet more text
    </section>
</test>


Desired output:

<test>
    <section>
    preamble
        <section>
            <h1>section 1</h1>
            text
            <b>bolded text</b>
            more text
        </section>
        <section>
            <h1>section 2</h1>
            yet more text
        </section>
    </section>
</test>



Actual output:

<test>
    <section>
        <section>
            <h1>section 1</h1>
            <b>bolded text</b>
        </section>
        <section>
            <h1>section 2</h1>
        </section>
    </section>
</test>



----- Original Message ----
From: Michael Kay <mike@xxxxxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Tue, June 15, 2010 12:09:44 PM
Subject: Re:  group-starting-with drops child text nodes - workaround?

There are plenty of people on this list willing and able to show you how 
to fix your code. But first you need to show them your code. If it's not 
doing what you want, that's because you wrote it wrong.

Michael Kay
Saxonica

On 15/06/2010 18:40, tom schmitter wrote:
> Hello,
>
> It seems that using the grouping method "group-starting-with" will cause child text nodes of the element that starts each group to be omitted from the resulting populations. eg, group-starting-with="subtitle":
>
> <subtitle/>
> text
>      <b>bolded text</b>
> more text
> <subtitle/>
> ...
>
> results in a population that looks like:
>
> <subtitle/>
>      <b>bolded text</b>
>
>
> I believe this is the expected behavior. If so, does anyone know of a workaround? ie, a way to somehow preserve the child text?
>
> For example, my first thought was to wrap the child text nodes in<p>s before performing the grouping, but of course this caused linebreaks to appear between the child text nodes and following inline elements (in the example above, linebreaks would appear between "text", "bolded text", and "more text").
>
> My ultimate objective is create hierarchy (in the example, for<subtitle>  to be the parent of all nodes between each subtitle). Is there a better way?
>
> Thanks
>
> Tim

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.