Home xml xslt difference between XSL: Text and text

xslt difference between XSL: Text and text

Author

Date

Category

For what or in what cases to use the & lt; xsl element: text & gt; in xSLT ?

here is an example code

& lt; body & gt;
    & lt; h1 & gt; & lt; xsl: value-of select = "Local-Name (/ *)" / & gt; & lt; / h1 & gt;
    & lt; ul & gt;
     & lt; xsl: for-each select = "buch" & gt;
      & lt; li & gt;
       & lt; xsl: value-of select = "title" / & gt; / & lt; xsl: value-of select = "Autor" / & gt; / & lt; xsl: value-of select = "Verlag" / & gt;
       & lt; br / & gt;
       & lt; xsl: text & gt; ISBN: & lt; / xsl: Text & gt;
       & lt; xsl: value-of select = "@ isbn" & gt; & lt; / xsl: value-of & gt;
      & lt; / li & gt;
     & lt; / xsl: for-each & gt;
    & lt; / ul & gt;
   & lt; / body & gt;

tried to write without the & lt; xsl element: text & gt; , the result is the same.

& lt; li & gt;
 & lt; xsl: value-of select = "title" / & gt; / & lt; xsl: value-of select = "Autor" / & gt; / & lt; xsl: value-of select = "Verlag" / & gt;
 & lt; br / & gt;
 ISBN:
 & lt; xsl: value-of select = "@ isbn" & gt; & lt; / xsl: value-of & gt;
& lt; / li & gt;

What is the power of this element?


Answer 1, Authority 100%

Using XSL: Text You can accurately control the output of the space characters.

Under your XSL code I took such an XML:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Test & GT;
  & lt; buch isbn = "1" & gt;
    & lt; Title & gt; Title1 & lt; / title & gt;
    & lt; autor & gt; autor1 & lt; / autor & gt;
    & lt; verlag & gt; ver1.0 & lt; / verlag & gt;
  & lt; / buch & gt;
  & lt; buch isbn = "2" & gt;
    & lt; Title & gt; Title2 & lt; / title & gt;
    & lt; autor & gt; autor2 & lt; / autor & gt;
    & lt; verlag & gt; ver2.0 & lt; / verlag & gt;
  & lt; / buch & gt;
& lt; / Test & gt;

First option of your code, with XSL: Text gives such a conclusion:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Body & gt;
 & lt; h1 & gt; test & lt; / h1 & gt;
 & lt; ul & gt;
  & lt; li & gt; title1 / autor1 / ver1.0 & lt; br / & gt; ISBN: 1 & lt; / li & gt;
  & lt; li & gt; title2 / autor2 / ver2.0 & lt; br / & gt; ISBN: 2 & lt; / li & gt;
 & lt; / ul & gt;
& lt; / body & gt;

The second option gives the following:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Body & gt;
 & lt; h1 & gt; test & lt; / h1 & gt;
 & lt; ul & gt;
  & lt; li & gt; title1 / autor1 / ver1.0 & lt; br / & gt;
            ISBN:
            1 & lt; / li & gt;
  & lt; li & gt; title2 / autor2 / ver2.0 & lt; br / & gt;
            ISBN:
            2 & lt; / li & gt;
 & lt; / ul & gt;
& lt; / body & gt;

As you can see, in the second case, the ISBN value: it was copied with spaces in front of it, as well as with the row translations.


To not be misunderstanding, I will give the full text of the XSL transformation, which I used:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/xsl/transform" & gt;
  & lt; XSL: Output Method = "XML" indent = "Yes" / & gt;
  & lt; xsl: template match = "@ * | node ()" & gt;
    & lt; Body & gt;
      & lt; h1 & gt;
        & lt; xsl: value-of select = "Local-Name (/ *)" / & gt;
      & lt; / h1 & gt;
      & lt; ul & gt;
        & lt; xsl: for-each select = "buch" & gt;
          & lt; li & gt;
            & lt; xsl: value-of select = "title" / & gt; / & lt; xsl: value-of select = "Autor" / & gt; / & lt; xsl: value-of select = "Verlag" / & gt;
            & lt; br / & gt;
            & lt;! - & lt; xsl: text & gt; ISBN: & LT; / XSL: Text & gt; - & gt;
            ISBN:
            & lt; xsl: value-of select = "@ isbn" & gt; & lt; / xsl: value-of & gt;
          & lt; / li & gt;
        & lt; / xsl: for-each & gt;
      & lt; / ul & gt;
    & lt; / body & gt;
  & lt; / xsl: template & gt;
& lt; / xsl: stylesheet & gt;

Answer 2, Authority 40%

In the style table, the text can be created for outputting results to the literal tree using the & LT; XSL: Text & GT; or without it. However, when using this item, you can control the spaces created by the style sheet to a certain extent. For example, to improve the readability of the style sheet, you can record each element of the template on a separate line and use indents in some lines. In this case, the gaps become an integral part of the template rule. It can be both desirable and undesirable conversion effect.

Sometimes you need to display a space to split two values. In this case, you can use the item. Spaces enclosed inside the & Lt; XSL: Text & GT; , are displayed in the result tree.

& LT element; xsl: Text & gt ; on MSDN Library

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions