I want to produce a newline for text output in XSLT. Any ideas?
相关问题
- XML - XSLT - document() function inside count() fu
- Using XSLT to select after EACH instance in a stri
- XSLT open other xml files
- How to use MSbuild property in TransformXml task?
- Using asp objects in .NET - Max compatibility
相关文章
- xslt localization
- convert xml to soap request using xslt transformat
- XALAN register Extension Function like in SAXON
- How to group using XSLT
- How to reformat XML with group-adjacent (XSLT)
- AddExtensionObject - Performance
- Transforming HTML nodes with XSLT in chrome/webkit
- visual studio 2015 xsl debugging transformation fa
My favoured method for doing this looks something like:
Then, whenever you want to output a newline (perhaps in csv) you can output something like:
I've used this technique when outputting sql from xml input. In fact, I tend to create variables for commas, quotes and newlines.
The following XSL code will produce a newline (line feed) character:
For a carriage return, use:
I've noticed from my experience that producing a new line INSIDE a
<xsl:variable>
clause doesn't work. I was trying to do something like:Anything I tried to put in that "new line" (the empty
<xsl:text>
node) just didn't work (including most of the simpler suggestions in this page), not to mention the fact that HTML just won't work there, so eventually I had to split it to 2 variables, call them outside the<xsl:variable>
scope and put a simple<br/>
between them, i.e:Yeah, I know, it's not the most sophisticated solution but it works, just sharing my
frustrationexperience with XSLs ;)I second Nic Gibson's method, this was always my favorite:
However I have been using the Ant task <echoxml> to create stylesheets and run them against files. The task will do attribute value templates, e.g. ${DSTAMP} , but is also will reformat your xml, so in some cases, the entity reference is preferable.
I couldn't just use the
<xsl:text>
</xsl:text>
approach because if I format the XML file using XSLT the entity will disappear. So I had to use a slightly more round about approach using variablesYou can try,
It will work.