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

Re: XSLT 2.0 & Grouping for-each-group - RESEND

Subject: Re: XSLT 2.0 & Grouping for-each-group - RESEND
From: Mark Brand <mark.brand@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 07 Aug 2003 19:41:43 +1000
xslt for each group
* Michael Kay

<snip>

Clearly the XSLT must be well-formed XML, so the closing tags have to be
properly nested, and they will then also be properly nested in the
result document. In fact, it's impossible to output a document in which
the tags aren't properly nested! So I don't think I understand the
question.

</snip>

Hi Micheal

I am being vague, because i don't understand all the issues - this is my first transform. So
then, I don't think then I understand your second option then. This is the code that i wrote below (Listing 1)


(Listing 1)
<?xml version="1.0"?>
<xsl:transform
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:f="http://www.elegalpublishing.com/namespace"
	version="2.0"
	exclude-result-prefixes="f xs">

	<xsl:template match="Document/DocumentBody">
		<REGULATION>
		<xsl:for-each-group select="Paragraph" group-starting-with="*[@StyleName='PART']">
			<xsl:apply-templates select="."/>
		</xsl:for-each-group>
		</REGULATION>
	</xsl:template>

	<xsl:template match="Paragraph">
		 /* This is where opening ELEMENT should go EG. <PART> or <DIVISION> */
		/* and but where does the closing element go EG  </PART> or </DIVISION> */
		    <xsl:copy-of select="child::node()"/>
		    <xsl:for-each-group select="current-group() except ." group-starting-with="*[@StyleName=f:child(@StyleName)]">
				<xsl:apply-templates select="."/>
			</xsl:for-each-group>
	</xsl:template>

<xsl:function name="f:child"> <xsl:param name="level"/>
<xsl:choose>
<xsl:when test="$level='PART'">
DIVISION
</xsl:when>


				<xsl:when test="$level='DIVISION'">
					REGULATION
				</xsl:when>

				<xsl:when test="$level='REGULATION'">
					SUB-REGULATION
				</xsl:when>
			</xsl:choose>
	</xsl:function>
</xsl:transform>

Thanks Mark Brand






Michael Kay wrote:


* Mark Brand

Hi

I have further questions on the fragments posted earlier. I did try implementing both options but had some questions ...

Q1. <snip>
<xsl:for-each-group select="current-group() except "." group-starting-with="*[@StyleName='DIVISION']">
</snip>


With this line of code, i found that it would execute (enter the for-each-group
loop) even if there wasn't a DIVISION item in the group. How do I stop the loop being entered if the group-starting-with entry is not in the list. I have tried an if statement after the loop has been entered but it is too late then for my purposes.



This reads to me like


<xsl:if test="current-group()/*[@StyleName='DIVISION']">
<xsl:for-each-group select="current-group() except "." group-starting-with="*[@StyleName='DIVISION']">
...
</xsl:if>


But I may have misunderstood the requirement. What do you want to happen
if there isn't a DIVISION item in the group?



Q2. <snip>
<Part Category="{@StyleName}">
<xsl:copy-of select="child::node()"/>
<xsl:for-each-group select="current-group() except ."
group-starting-with="*[@StyleName=f:child(@StyleName)]">
<xsl:apply-templates select="."/>
</snip>


With this piece of code from the second option where would you put the closing tags, where-ever i put them they would all output after everything else instead of in a nested fashion.



Clearly the XSLT must be well-formed XML, so the closing tags have to be
properly nested, and they will then also be properly nested in the
result document. In fact, it's impossible to output a document in which
the tags aren't properly nested! So I don't think I understand the
question.

Michael Kay


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list






XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


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.