How to use <XSL:Text>

Jammerules
Jammerules used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
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
<b>
literal text goes here
</b>

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

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

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)Information Architect
Top Expert 2006

Commented:
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

http://nwalsh.com/docs/tutorials/xsl/

Author

Commented:
Thanks Gertone. I am working on the example you gave. I will report with any questions in a little bit.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

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

My XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XSLTFile_ex5.xslt"?>
<Profiles>
      <Profile>
          <Salutation>Mr. </Salutation>  
          <FirstName>George</FirstName>
          <LastName>Bush
              <Suffixes>
                  <Suffix>Sr</Suffix> 
              </Suffixes>
          </LastName>
          <Description>was the prez of the United States
          </Description>
      </Profile>
</Profiles>

Open in new window


My XSL:
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
  <xsl:output method="html"/>

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

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

Open in new window

So in this context, where can one use XSL:Text and why?
Information Architect
Top Expert 2006
Commented:
Here there is no reason for using xsl:text.
it is only useful if you want to write a literal text to the output tree

In your other question there is use for xsl:text

                    <td bgcolor="lightgray"> Republican President </td>

I would write

                    <td bgcolor="lightgray">
                        <xsl:text> Republican President </xsl:text>
                    </td>
Reads better in my opinion and it guarantuees correct preservation of the spaces
(though they don't matter in HTML output)

Author

Commented:
Hopefully, its use is as limited as that :). Thanks!
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
welcome

"Hopefully"???
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)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial