Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: XSLT help please

  1. #11
    Join Date
    May 2006
    Beans
    1,787

    Re: XSLT help please

    Quote Originally Posted by Reiger View Post
    If this is text.xsl:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                    version="1.0">
      <xsl:template match="/">
        <root><xsl:text>This is the HTML entity for the © symbol: &amp;copy;</xsl:text></root>
      </xsl:template>
    </xsl:stylesheet>
    And this is test.xml:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <root/>
    Then the XSLT processor should output:
    Code:
    <root>
    This is the HTML entity for the © symbol: &copy;
    </root>
    Change output method to "text" and the <root> tags are removed, but the text stays the same.

    That works for any entity you care to enter because the &amp; is converted to & in the output. Now the only thing to worry about is whether or not the parser which reads the output of the XSLT understands &copy;. If not, then use the Unicode code point because any conforming XML parser is required to handle that.
    I'm not qualified to say whether you or xsltproc or neither is wrong, but what I get is this:

    Code:
    <?xml version="1.0"?>
    <root>This is the HTML entity for the © symbol: &amp;copy;</root>

  2. #12
    Join Date
    Jul 2008
    Beans
    1,491

    Re: XSLT help please

    Well obviously, xsltproc is wrong. No, seriously, it is wrong. The content of <xsl:text> is PCDATA as per the XSLT spec, so &amp; is & therefore, &amp;copy; is &copy;.

    But you can work around this. You said the XML output was not very pretty once you added output-escaping to the mix, however if I change the template to this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                    version="1.0">
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="/">
        <root>
          <foo><xsl:text disable-output-escaping="yes">This is the HTML entity for the © symbol: &amp;copy;</xsl:text></foo>
        </root>
      </xsl:template>
    </xsl:stylesheet>
    And run xsltproc on it:
    Code:
    $ xsltproc test.xsl test.xml
    <?xml version="1.0"?>
    <root>
      <foo>This is the HTML entity for the © symbol: &copy;</foo>
    </root>
    ... then maybe just file a bug report against xsltproc?

  3. #13
    Join Date
    Oct 2006
    Location
    Slovakia
    Beans
    590
    Distro
    Xubuntu 11.10 Oneiric Ocelot

    Re: XSLT help please

    Guys, many thanks for your replies. I'm considering filing a bug, probably through Launchpad.

    Anyway, even if that bug was fixed, it wouldn't solve my problem, since the <xsl:text> element breaks up indentation and I can't wrap it in a meaningless element, like Reiger did (<foo>), to restrict that indentation breakup. There is simply no such acceptable element in DocBook.

    I sort of gave up and instead of my desired inclusion link, I have XSLT produce a meaningless element <span class="replacement"/>, and then I have "sed" run through the file and replace that element with "&inclusion-link;".

    Guaranteed to work like a charm on every Linux/Unix and gives me valid and neatly-formatted XML DocBook file.
    בראשית ברא אלהים את השמים ואת הארץ׃

  4. #14
    Join Date
    Jul 2008
    Beans
    1,491

    Re: XSLT help please

    You don't need the <foo> element. I added it to see if it would produce the problem you described earlier, but it didn't -- looks like xsltproc can be made to behave with the indent="yes" option in the <xslutput> element.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •