XSL if else condition

We can achieve if else by using below code <xsl:choose> <xsl:when test=”something to test”> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> So here is what I did <h3>System</h3> <xsl:choose> <xsl:when test=”autoIncludeSystem/autoincludesystem_info/@mdate”> <!– if attribute exists–> <p> <dd><table border=”1″> <tbody> <tr> <th>File Name</th> <th>File Size</th> <th>Date</th> <th>Time</th> <th>AM/PM</th> </tr> <xsl:for-each select=”autoIncludeSystem/autoincludesystem_info”> <tr> <td valign=”top” ><xsl:value-of select=”@filename”/></td> <td valign=”top” ><xsl:value-of … Read more

XSL if: test with multiple test conditions

Thanks to @IanRoberts, I had to use the normalize-space function on my nodes to check if they were empty. <xsl:if test=”((node/ABC!=”) and (normalize-space(node/DEF)=”) and (normalize-space(node/GHI)=”))”> This worked perfectly fine. </xsl:if>

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

Splitting XML into multiple files with XSLT

Responding to your comment on @Dimitre’s answer… You wrote, <xsl:template match=”https://stackoverflow.com/”> <xsl:for-each select=”elem/file”> <xsl:result-document method=”xml” href=”https://stackoverflow.com/questions/4036233/file_{@id}-output.xml”> <xsl:copy-of select=”.”/> </xsl:result-document> </xsl:for-each> </xsl:template> This doesn’t quite match your XML, which has rootelem as an outermost element, and your comment says root as an outermost element. You probably want something like this: <xsl:template match=”/root”> <xsl:for-each select=”elem/file”> <xsl:result-document method=”xml” … Read more

Tools for debugging xslt

If you want to do “printf-style” debugging and don’t want to litter your output with debugging data, use the <xsl:message> tag to generate debugging output while processing the stylesheet. With the terminate=”yes” attribute you can even halt the processing of the stylesheet.

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′)”/>

Setting xsl:value-of into an href attribute and the text field of a link in an XSLT

<xsl:text> defines a text section in an XSL document. Only real, plain text can go here, and not XML nodes. You only need <xsl:value-of select=”actionUrl”/>, which will print text anyways. <xsl:element name=”a”> <xsl:attribute name=”href”> <xsl:value-of select=”actionUrl”/> </xsl:attribute> <xsl:value-of select=”actionUrl”/> </xsl:element>

Format a date in XML via XSLT

Here are a couple of 1.0 templates that you can use:- <xsl:template name=”formatDate”> <xsl:param name=”dateTime” /> <xsl:variable name=”date” select=”substring-before($dateTime, ‘T’)” /> <xsl:variable name=”year” select=”substring-before($date, ‘-‘)” /> <xsl:variable name=”month” select=”substring-before(substring-after($date, ‘-‘), ‘-‘)” /> <xsl:variable name=”day” select=”substring-after(substring-after($date, ‘-‘), ‘-‘)” /> <xsl:value-of select=”concat($day, ‘ ‘, $month, ‘ ‘, $year)” /> </xsl:template> <xsl:template name=”formatTime”> <xsl:param name=”dateTime” /> <xsl:value-of select=”substring-after($dateTime, … Read more

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