xslt how to add attributes to copy-of

xsl:copy-of performs a deep copy of the selected node, but doesn’t provide an opportunity to alter it. You will want to use xsl:copy and then add additional nodes inside. xsl:copy just copies the node and namespace attributes, but not the regular attributes and child nodes, so you will want to ensure that you apply-templates to … Read more

Performance: call-template vs apply-template

As with all performance questions, the answer will depend on your particular configuration (in particular the XSLT processor you’re using) and the kind of processing that you’re doing. <xsl:apply-templates> takes a sequence of nodes and goes through them one by one. For each, it locates the template with the highest priority that matches the node, … Read more

Increment a value in XSLT

XSLT is a functional language and among other things this means that variables in XSLT are immutable and once they have been defined their value cannot be changed. Here is how the same effect can be achieved in XSLT: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:strip-space elements=”*”/> <xsl:template match=”https://stackoverflow.com/”> <posts> <xsl:for-each select=”data/posts/entry”> <xsl:variable name=”i” select=”position()” … Read more

Inserting a line break in a PDF generated from XSL FO using

You could also replace <br/> with &#xA; and add a linefeed-treatment=”preserve” attribute to your <fo:block>. Something like: <fo:block linefeed-treatment=”preserve”>This is an example Description.&#xA;List item 1&#xA;List item 2&#xA;List item 3&#xA;List item 4</fo:block> Edit Some users may need to use \n instead of &#xA; depending on how they are creating the XML. See Retain the &#xA; during … Read more

How to add multiple test conditions in ‘test’ attribute expression of tag

<xsl:if test=”$var=”ab” | $var=”bc” | $var=”ca” “> This is wrong — you are using the XPath union operator | on boolean values. Solution: use the XPath or operator: <xsl:if test=”$var=”ab” or $var=”bc” or $var=”ca” “> The above XPath expression (the value of the test attribute) can be optimized, so that only one comparison is made … Read more

difference between xsl:param and xsl:variable

The difference is that the value of an xsl:param could be set outside the context in which it is declared. For example, see: <xsl:template …> <xsl:param name=”p” select=”‘x'” /> <xsl:variable name=”v” select=”‘y'” /> … then you know that $v will always give you the string ‘y’. But for $p the string ‘x’ is only a … Read more

Division in XSLT

XPath uses div for division since slashes are used as separators. $<xsl:value-of select=”format-number(//Applications/AveAnnualVolume div 12,’###,###,##0.00′)”/>

XSLT xsl:sequence. What is it good for..?

<xsl:sequence> on an atomic value (or sequence of atomic values) is the same as <xsl:copy-of> both just return a copy of their input. The difference comes when you consider nodes. If $n is a single element node, eg as defined by something like <xsl:variable name=”n” select=”/html”/> Then <xsl:copy-of select=”$n”/> Returns a copy of the node, … Read more

XSLT : Looping from 1 to 60

In XSLT 2.0, <xsl:for-each select=”1 to 60″>…</xsl:for-each> But I guess that you must be using XSLT 1.0, otherwise you wouldn’t be asking. In XSLT 1.0 you should use recursion: a template that calls itself with a counter that’s incremented on each call, and the recursion terminates when the required value is reached. Alternatively there’s a … Read more

tech