How do I format text in between xsl:text tags?
-
09-06-2019 - |
Question
I have an xslt sheet with some text similar to below:
<xsl:text>I am some text, and I want to be bold</xsl:text>
I would like some text to be bold, but this doesn't work.
<xsl:text>I am some text, and I want to be <strong>bold<strong></xsl:text>
The deprecated b tag doesn't work either. How do I format text within an xsl:text tag?
Solution
You don't. xsl:text
can only contain text nodes and <strong>
is an element node, not a string that starts with less-than character; XSLT is about creating node trees, not markup. So, you have to do
<xsl:text>I am some text, and I want to be </xsl:text>
<strong>bold<strong>
<xsl:text> </xsl:text>
OTHER TIPS
Try this:
<fo:inline font-weight="bold"><xsl:text>Bold text</xsl:text></fo:inline>
<xsl:text disable-output-escaping="yes">I want to be <strong>bold<strong> </xsl:text>
XSL-FO formatting should be able to do that, see the W3Schools tutorial.
The answer for this depends on how much formatting is needed in the content and also where you get content from. If you have less content and less formatting then you can use what jelovirt suggested
<xsl:text>I am some text, and I want to be </xsl:text>
<strong>bold<strong>
<xsl:text> </xsl:text>
However if your content has large formatting then what David Medinets suggests is better way to do it
<xsl:text disable-output-escaping="yes">
We have some instructions to print on UI. The set of instructions is huge and of course we read those from XML file.
In such cases the above method is easy to use and maintain too. That is because the content is provided by technical writers. They have no knowledge of XSL. They know using HTML tags and they can easily edit the XML file.