[prev in list] [next in list] [prev in thread] [next in thread]
List: xsl-list
Subject: Re: [xsl] grouping like items into one
From: Fred Christian <fredc () kbooks ! com>
Date: 2009-01-23 18:25:03
Message-ID: 497A0B7F.2010702 () kbooks ! com
[Download RAW message or body]
Thanks so much, both examples worked perfectly.
And I will remember about creating new messages instead of replying to
start a thread.
Michael Kay wrote:
> <xsl:template match="DD">
> <DD>
> <xsl:for-each-group select="text" group-adjacent="@border">
> <xsl:choose>
> <xsl:when test="current-grouping-key()='single'">
> <span class="border">
> <xsl:apply-templates select="current-group()"/>
> </
> </
> <xsl:otherwise>
> <xsl:apply-templates select="current-group()"/>
> </
> </
> </
> </
> </
>
> <xsl:template match="text[@italic='true']">
> <i><xsl:value-of select="."/></i>
> </
>
> <xsl:template match="text[@italic='false']">
> <xsl:value-of select="."/>
> </
>
> Michael Kay
> http://www.saxonica.com/
>
>
>
>> -----Original Message-----
>> From: Fred Christian [mailto:fredc@kbooks.com]
>> Sent: 23 January 2009 01:37
>> To: xsl-list@lists.mulberrytech.com
>> Subject: [xsl] grouping like items into one
>>
>> I know I have done this with xsl 1.0 before and could figure
>> it out, but 1.0 is painful :) So I am trying to figure it out
>> with 2.0 and am getting stuck. I am running into that "how do
>> I know what to look up if I don't know how to spell it" jam.
>> I looked at the xsl:for-each-group element, but I don't think
>> that will work in this situation.
>> Someone want to take a whack at it?
>>
>>
>> I want to group bordered text into one border <span>, but
>> leave italic text ( and other styles ) in individual nodes.
>>
>> _______Source XML__________________
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DD>
>> <text italic="false" border="">a </text> <text italic="false"
>> border="single">b </text> <text italic="true"
>> border="single">c </text> <text italic="true" border="">d
>> </text> <text italic="false" border="">e </text> <text
>> italic="false" border="single">f </text> <text italic="false"
>> border="single">g </text> <text italic="false" border="">h
>> </text> <text italic="true" border="single">i </text> <text
>> italic="true" border="">j </text> </DD>
>>
>> _____Current output (formated for
>> readability)________________ a <span class="border">b </span>
>> <span class="border"><i>c </i></span> <i>d </i> e <span
>> class="border">f </span> <span class="border">g </span> h
>> <span class="border"><i>i </i></span> <i>j </i>
>>
>>
>> ____ Desired output (formated for readability) ______________
>> ____ Note how there is one <span....> around b <i>c </> and
>> around "f
>> g " ___
>> a
>> <span class="border">b <i>c </i></span>
>> <i>d </i>
>> e
>> <span class="border">f g </span>
>> h
>> <span class="border"></span>
>> <i>i </i>
>> <i>j </i>
>>
>> _____________ current xsl _______________
>> <xsl:stylesheet version="2.0"
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:saxon="http://saxon.sf.net/"
>> exclude-result-prefixes="xs saxon">
>>
>> <xsl:template match="/DD">
>> <xsl:apply-templates/>
>> </xsl:template>
>>
>> <xsl:template match="text">
>> <xsl:choose>
>> <xsl:when test="@border='single'">
>> <span class="border"><xsl:apply-templates select="."
>> mode="moreStyles"/></span>
>> </xsl:when>
>> <xsl:otherwise><xsl:apply-templates select="."
>> mode="moreStyles"/></xsl:otherwise>
>> </xsl:choose>
>> </xsl:template>
>>
>> <xsl:template match="text" mode="moreStyles">
>> <xsl:choose>
>> <xsl:when test="./@italic='true'">
>> <i><xsl:apply-templates/></i>
>> </xsl:when>
>> <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
>> </xsl:choose>
>> </xsl:template>
>>
>> </xsl:stylesheet>
>>
>>
>> --~------------------------------------------------------------------
>> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
>> or e-mail: <mailto:xsl-list-unsubscribe@lists.mulberrytech.com>
>> --~--
>>
>>
>
>
> --~------------------------------------------------------------------
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@lists.mulberrytech.com>
> --~--
>
>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@lists.mulberrytech.com>
--~--
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic