Avatar of Jammerules
 asked on

How to use <XSL:Text>

Hi! Can someone give a couple of examples (one easy and one complex :) ) that use <XSL:Text>, please?

I looked at W3Schools example and it really did not give enough information on it. BTW, I am noob to XML and XSL! Thanks.

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
Gertone (Geert Bormans)

there are no complex examples with xsl:text

<xsl:text>literal text goes here</xsl:text>

Open in new window

is about the most complex you can get

xsl:text only accepts literal text content
it creates a text node

look at this example
literal text goes here

a <b> element would be created with thetext string in it, but also the line breaks (and some XSLT processors even do the wrong thing here

<xsl:text>literal text goes here</xsl:text>

now the linebreaks will not be copied to the result because they are not part of the text node
so you would use xsl:text to better control the whitespace
Gertone (Geert Bormans)

w3schools is really a bad resource. It just list keywords and the examples are outdated and they don't differentiate between XPath 1 and XPath2 functions

this one is very old, but still relevant to get the basics
from this one you would actually learn something


Thanks Gertone. I am working on the example you gave. I will report with any questions in a little bit.
Your help has saved me hundreds of hours of internet surfing.

Umm...pardon me for not being able to catch your answer, but let's try it differently:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile_ex5.xslt"?>
          <Salutation>Mr. </Salutation>  
          <Description>was the prez of the United States

Open in new window

  <xsl:output method="html"/>

  <xsl:template match="/"> 
    <xsl:apply-templates select="Profiles/Profile"/>  

  <xsl:template match="Profile">   
          <xsl:value-of select="."/>            

Open in new window

So in this context, where can one use XSL:Text and why?
Gertone (Geert Bormans)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Hopefully, its use is as limited as that :). Thanks!
Gertone (Geert Bormans)


Take my word for it, it is as limited as that.
It just creates a text node.
And I recommend using it in the example above

(there is an attribute that allows you to switch off output escaping,
but that is advanced and I highly recommend that you don't use it,
so for now, you know all you need to know on xsl:text)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.