How to convert newline into with XSLT? [duplicate]

This transformation: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:template match=”t”> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match=”text()” name=”insertBreaks”> <xsl:param name=”pText” select=”.”/> <xsl:choose> <xsl:when test=”not(contains($pText, ‘&#xA;’))”> <xsl:copy-of select=”$pText”/> </xsl:when> <xsl:otherwise> <xsl:value-of select=”substring-before($pText, ‘&#xA;’)”/> <br /> <xsl:call-template name=”insertBreaks”> <xsl:with-param name=”pText” select= “substring-after($pText, ‘&#xA;’)”/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> when applied on this XML document: <t>Line1 Line2 Line3 </t> … Read more

How do you output the current element path in XSLT?

The currently accepted answer will return incorrect paths. For example, the element Ele2 in the OP sample XML would return the path /Doc[1]/Ele2[2]. It should be /Doc[1]/Ele2[1]. Here’s a similar XSLT 1.0 template that returns the correct paths: <xsl:template name=”genPath”> <xsl:param name=”prevPath”/> <xsl:variable name=”currPath” select=”concat(“https://stackoverflow.com/”,name(),'[‘, count(preceding-sibling::*[name() = name(current())])+1,’]’,$prevPath)”/> <xsl:for-each select=”parent::*”> <xsl:call-template name=”genPath”> <xsl:with-param name=”prevPath” select=”$currPath”/> … Read more

XML Attributes vs Elements [duplicate]

There is an article titled “Principles of XML design: When to use elements versus attributes” on IBM’s website. Though there doesn’t appear to be many hard and fast rules, there are some good guidelines mentioned in the posting. For instance, one of the recommendations is to use elements when your data must not be normalized … Read more