|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Group problem with blank elements
Hi Mike,
I was trying to solve this problem the XSLT 1.0 way,
but am facing some problem. I am using Saxon 6.5.3.
The XML file I used is -
<?xml version="1.0" encoding="UTF-8"?>
<root>
<statement-message>Your account is now seriously in
arrears.
To</statement-message>
<statement-message>avoid further action a payment
of</statement-message>
<statement-message>$82.00 is required immediately.
Any</statement-message>
<statement-message>purchases will now be
declined.</statement-message>
<statement-message>
</statement-message>
<statement-message> More text </statement-message>
<statement-message>
</statement-message>
<statement-message>
</statement-message>
<statement-message>
</statement-message>
</root>
The XSLT file I used was -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="statement-message" />
</xsl:stylesheet>
This is a usual modified identity stylesheet..
But I am getting output -
<?xml version="1.0" encoding="utf-8"?>
Press any key to continue . . .
Can you please tell, is there problem somewhere?
Regards,
Mukul
--- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> When you do xsl:value-of select="." directly inside
> xsl:for-each-group, "."
> refers to the first item in the group. You want to
> output the concatenation
> of all the items in the group, which you can do with
>
> string-join(current-group(), ' ')
>
> Also, each empty element that's followed by another
> empty element is being
> treated as a group containing a single member.
>
> I think I would tackle this using
>
> group-adjacent="string-length(.)=0"
>
> This will create a sequence of groups, alternating a
> sequence of empty
> elements with a sequence of non-empty elements. You
> can then test if the
> first element in the current group is non-empty, and
> if so, output the
> string-join as above.
>
> Michael Kay
> http://www.saxonica.com/
>
> > -----Original Message-----
> > From: Ed Yau [mailto:eyau@xxxxxxxxxxxxxxx]
> > Sent: 30 June 2005 18:31
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Group problem with blank elements
> >
> > Hiya,
> >
> > Having loads of trouble with this. On the face of
> it a really easy
> > problem.
> > I have a bunch of elements like so:
> >
> > <statement-message>Your account is now seriously
> in arrears.
> > To</statement-message>
> >
> > <statement-message>avoid further action a payment
> > of</statement-message>
> >
> > <statement-message>$82.00 is required immediately.
> > Any</statement-message>
> >
> > <statement-message>purchases will now be
> declined.</statement-message>
> >
> > <statement-message>
> > </statement-message>
> >
> > <statement-message> More text
> </statement-message>
> >
> > <statement-message>
> > </statement-message>
> >
> > <statement-message>
> > </statement-message>
> >
> > <statement-message>
> > </statement-message>
> >
> > I want to strip out the empty tags and merge
> adjacent elements as
> > follows:
> >
> > <statement-message> Your account is now seriously
> in arrears. To avoid
> > further action a payment of
> > 82.00 is required immediately. Any purchases will
> now be
> > declined.</statement-message>
> >
> > <statement-message> More text
> </statement-message>
> >
> > My code at the moment is:
> > <xsl:for-each-group select="statement-message"
> >
>
group-ending-with="statement-message[string-length(normalize-s
> > pace(follo
> > wing-sibling::statement-message[1]))=0]">
> > <statement-message>
> > <xsl:value-of select="."/>
> > </statement-message>
> > </xsl:for-each-group>
> >
> > My understanding of this is that it should start
> grouping from the 1st
> > statement message, with the groups ending as soon
> as an empty
> > element is
> > reached. The empty tags at the end would still be
> there, but at least
> > it should do the merge. However, the result looks
> like:
> >
> > <statement-message>Your account is now
> seriously in arrears.
> > To</statement-message>
> > <statement-message>
> > </statement-message>
> > <statement-message> More text
> </statement-message>
> > <statement-message>
> > </statement-message>
> > <statement-message>
> > </statement-message>
> > <statement-message>
> > </statement-message>
> >
> > So where am I going wrong?
> >
> > Ed
>
>
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








