[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] grouping by attribute
Can anyone suggest a better way to achieve the following... I need to group the xml elements category and place each category in a separate table. For example: my xml file is... <test> <item category="aaa">1xxxxxxxaaa</item> <item category="bbb">2xxxxxxxbbb</item> <item category="zzz">3xxxxxxxzzz</item> <item category="bbb">4xxxxxxxbbb</item> <item category="yyy">5xxxxxxxyyy</item> </test> Currently I use the following XSL which works but it requires I hardcode each attribute. Is this where I should use a xsl:variable? <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns="http://www.w3.org/TR/REC-html40" result-ns=""> <xsl:template match="*|/"><xsl:apply-templates/></xsl:template> <xsl:template match="test"> <xsl:sort select="item@category"/> <p/><table border="1"> <xsl:apply-templates select="item[@category='aaa']"/> </table> <p/><table border="1"> <xsl:apply-templates select="item[@category='bbb']"/> </table> <p/><table border="1"> <xsl:apply-templates select="item[@category='yyy']"/> </table> <p/><table border="1"> <xsl:apply-templates select="item[@category='zzz']"/> </table> </xsl:template> <xsl:template match="item[@category='aaa']"> <tr><td><xsl:value-of select="."/></td></tr> </xsl:template> <xsl:template match="item[@category='bbb']"> <tr><td><xsl:value-of select="."/></td></tr> </xsl:template> <xsl:template match="item[@category='yyy']"> <tr><td><xsl:value-of select="."/></td></tr> </xsl:template> <xsl:template match="item[@category='zzz']"> <tr><td><xsl:value-of select="."/></td></tr> </xsl:template> <xsl:template match="text()"><xsl:value-of select="."/></xsl:template> </xsl:stylesheet> regards Richard XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|