Link to home
Start Free TrialLog in
Avatar of Jammerules
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
<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
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/
Avatar of Jammerules
Jammerules

ASKER

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:

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?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
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!
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)