Link to home
Start Free TrialLog in
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 Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

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
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
Avatar of Jammerules


Thanks Gertone. I am working on the example you gave. I will report with any questions in a little bit.
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?
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hopefully, its use is as limited as that :). Thanks!

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)