how to apply group by on xslt elements

In XSLT 1.0, using Muenchian grouping. <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”xml” indent=”yes” /> <xsl:key name=”division” match=”User” use=”@Division” /> <xsl:template match=”Users”> <AllUsers> <xsl:apply-templates select=”User[generate-id(.)=generate-id(key(‘division’,@Division)[1])]”/> </AllUsers> </xsl:template> <xsl:template match=”User”> <Division value=”{@Division}”> <xsl:for-each select=”key(‘division’, @Division)”> <User> <id><xsl:value-of select=”@id” /></id> <name><xsl:value-of select=”@name” /></name> </User> </xsl:for-each> </Division> </xsl:template> </xsl:stylesheet> In XSLT 2.0, use xsl:foreach-group <xsl:output method=”xml” indent=”yes” /> <xsl:template match=”Users”> … Read more

How to use XSLT to create distinct values

An XSLT 1.0 solution that uses key and the generate-id() function to get distinct values: <?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” encoding=”UTF-8″ indent=”yes”/> <xsl:key name=”product” match=”/items/item/products/product/text()” use=”.” /> <xsl:template match=”https://stackoverflow.com/”> <xsl:for-each select=”/items/item/products/product/text()[generate-id() = generate-id(key(‘product’,.)[1])]”> <li> <xsl:value-of select=”.”/> </li> </xsl:for-each> </xsl:template> </xsl:stylesheet>

XSL for-each: how to detect last node?

If you’re using XSLT 2.0, the canonical answer to your problem is <xsl:value-of select=”GroupsServed” separator=”, ” /> On XSLT 1.0, the somewhat CPU-expensive approach to finding the last element in a node-set is <xsl:if test=”position() = last()” />

Upgrading XSLT 1.0 to XSLT 2.0

What is involved in upgrading from XSLT 1.0 to 2.0? 1 – What are the possible reasons for upgrading? If you are an XSLT programmer you’ll benefit largely from the more convenient and expressive XSLT 2.0 language + XPath 2.0 and the new XDM (XPath Data Model). You may want to watch this XSLT 2.0 … Read more

XSLT: How to change an attribute value during ?

This problem has a classical solution: Using and overriding the identity template is one of the most fundamental and powerful XSLT design patterns: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:param name=”pNewType” select=”‘myNewType'”/> <xsl:template match=”node()|@*”> <xsl:copy> <xsl:apply-templates select=”node()|@*”/> </xsl:copy> </xsl:template> <xsl:template match=”property/@type”> <xsl:attribute name=”type”> <xsl:value-of select=”$pNewType”/> </xsl:attribute> </xsl:template> </xsl:stylesheet> When applied on this XML document: <t> … Read more

Using an HTML entity in XSLT (e.g.  )

You can use CDATA section <xsl:text disable-output-escaping=”yes”><![CDATA[&nbsp;]]></xsl:text> or you can describe &nbsp in local DTD: <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp “&#160;”> ]> or just use &#160; instead of &nbsp;

XSLT with XML source that has a default namespace set to xmlns

You need to declare the namespace in your XSLT, and use it in XPath expressions. E.g.: <xsl:stylesheet … xmlns:my=”http://www.mysite.com”> <xsl:template match=”/my:MyRoot”> … </xsl:template> </xsl:stylesheet> Note that you must provide some prefix if you want to refer to elements from that namespace in XPath. While you can just do xmlns=”…” without the prefix, and it will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)