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.
HTMLXML

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
<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)

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/
Jammerules

ASKER
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.
fblack61
Jammerules

ASKER
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
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
or
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
Jammerules

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

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)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.