Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Newbie question on Recusrion using XLST 1.0 Part 2

From: "Marco Mastrocinque" <mmfive@--------------->
To:
Date: 5/2/2005 3:08:00 AM
Hi Aron,
       I have multiple <division> elements, which are grouped by the
<employees> element, which has multiple <employee> elements. All the
<division> are unique (I took care of this using the unique, and key and
keyref tags in an xml schema, which is not shown.) Sorry I'm new to XPATH
and XSLT 1.0.

Thanks Marco Mastrocinque. 


-----Original Message-----
From: Aron Bock [mailto:aronbock@xxxxxxxxxxx] 
Sent: Monday, 2 May 2005 11:57 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Newbie question on Recusrion using XLST 1.0 Part 2

Marco, either I've not understood the complexity of what you're attempting, 
or you've unwittingly made it more comples than necessary.  If you don't 
have multiple <division> elements with the same @DID, the following is all 
you need:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
    <xsl:output method="text"/>

    <xsl:template match="/">
        <xsl:for-each select="company/division">
            <xsl:sort select="@DID"/>

            <xsl:value-of select="@DID"/>
            <xsl:text>&#xa;</xsl:text>

            <xsl:for-each select="employees/employee">
                <xsl:sort select="ENAME"/>

                <xsl:value-of select="concat('   ', @EID, ', ', ENAME, ', ',

OFFICE)"/>
                <xsl:text>&#xa;</xsl:text>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

For suggestions on handling more sophisticated grouping please see 
www.jenitennison.com

Regards,

--A

From: "Marco Mastrocinque" <mmfive@xxxxxxxxxxxxxxx>

<company>
    <division DID="Sal">
       <employees>
		<employee EID="EMP001">
		   <ENAME>Joe Blow</ENAME>
                <OFFICE>1.2.27</OFFICE>
                <BIRTHDATE>1963-08-01</BIRTHDATE>
		   <SALARY>28790</SALARY>
		</employee>
		<employee EID="EMP002">
		   <ENAME>John Doe</ENAME>
                <OFFICE>1.2.2</OFFICE>
                <BIRTHDATE>1970-08-01</BIRTHDATE>
		   <SALARY>29855</SALARY>
		</employee>
	</employees>
    </division>
    <division DID="SOF">
       <employees>
		<employee EID="EMM001">
		   <ENAME>Mark Smith</ENAME>
                <OFFICE>1.2.27</OFFICE>
                <BIRTHDATE>1966-08-01</BIRTHDATE>
		   <SALARY>35000</SALARY>
		</employee>
		<employee EID="EMM002">
		   <ENAME>John Doe</ENAME>
                <OFFICE>1.2.2</OFFICE>
                <BIRTHDATE>1977-08-01</BIRTHDATE>
		   <SALARY>40000</SALARY>
		</employee>
	</employees>
    </division>
</company>



I'm having using a recursive routine (see below) to display the following
elements and attributes:
1) The employee EID attribute such as 'EMP001', followed by
2) The element text of ENAME, such as 'Joe Blow',
3) The element text of OFFICE, such as '1.2.27'
4) The output must be formatted such that the employees of each division are
grouped together.

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent