Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: XSLT help please

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

    XSLT help please

    Hi y'all,

    it seems I can't overcome this peculiar problem: I need XSLT to produce this literal text in the output document (a DocBook section):

    Code:
    &some-bogus-name;
    And the output MUST NOT be enclosed in comments: <!-- -->

    I tried just about every combination of <xsl:text>, <xsl:comment>, CDATA and so on, but I just can't make it flush properly. I'm using xsltproc, and the parser either complains about an undefined entity, or encloses the problematic line in an HTML comment, or is the resulting xml file invalid and unable to be parsed by DocBook and DBLaTeX parsers...

    Any help will be much appreciated, thanks in advance!
    בראשית ברא אלהים את השמים ואת הארץ׃

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

    Re: XSLT help please

    Quote Originally Posted by mahy View Post
    Hi y'all,

    it seems I can't overcome this peculiar problem: I need XSLT to produce this literal text in the output document (a DocBook section):

    Code:
    &some-bogus-name;
    And the output MUST NOT be enclosed in comments: <!-- -->

    I tried just about every combination of <xsl:text>, <xsl:comment>, CDATA and so on, but I just can't make it flush properly. I'm using xsltproc, and the parser either complains about an undefined entity, or encloses the problematic line in an HTML comment, or is the resulting xml file invalid and unable to be parsed by DocBook and DBLaTeX parsers...

    Any help will be much appreciated, thanks in advance!
    Is it acceptable if it produces

    Code:
    &amp;some-bogus-name;
    instead? The result ought to be the same if the DocBook text is meant as XML input to something.

    To get that, just write it exactly like that in the xslt stylesheet.

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

    Re: XSLT help please

    Unfortunately, that is not acceptable, the DocBook parser does not accept it.

    I partially succeeded with this:

    Code:
    <xsl:text disable-output-escaping="yes">
    &#xa;&#x26;some-bogus-name;&#xa;
    </xsl:text>
    But there's still one problem: the resulting XML file, instead of being neatly formatted (pretty-printed), is vomited onto 4 mile-long lines. That does not affect machine-readability, but it does affect human-readability.
    בראשית ברא אלהים את השמים ואת הארץ׃

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

    Re: XSLT help please

    It seems highly unlikely an XML parser is unable to deal with &amp; which is defined by the XML spec AFAIK. However if you find your docbook tools are broken, maybe they will accept  instead? You could try outputing that, i.e:
    Code:
    <xsl:text>&amp;amp;some-bogus-name;</xsl:text>
    becomes:
    Code:
    <xsl:text>&amp;#26;some-bogus-name;</xsl:text>

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

    Re: XSLT help please

    Quote Originally Posted by Reiger View Post
    It seems highly unlikely an XML parser is unable to deal with &amp; which is defined by the XML spec AFAIK.
    But can you use "&amp;" as a substitute for ampersand in an entity name? E.g. the copyright sign has the entity name "&copy;". Can you use "&amp;copy;" instead? Of course not. What I need is to produce an "entity" by XSLT, which in reality is a DocBook include link and is to be picked up by a DocBook parser.

    As to that I already found a solution (written in my previous post), but the resulting XML is not pretty-printed, but garbled. That is the because of the <xsl:text> element which confuses the parser I use, xsltproc. (I already mailed libxslt developers about this issue.)

    The solution you propose is not necessary. What would really help is a workaround without any <xsl:text> element. Unless the libxslt developers suggest a workaround or admit and fix a bug, I'm afraid I'll have to introduce that problematic line by sed...
    בראשית ברא אלהים את השמים ואת הארץ׃

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

    Re: XSLT help please

    Quote Originally Posted by mahy View Post
    But can you use "&amp;" as a substitute for ampersand in an entity name? E.g. the copyright sign has the entity name "&copy;". Can you use "&amp;copy;" instead? Of course not. What I need is to produce an "entity" by XSLT, which in reality is a DocBook include link and is to be picked up by a DocBook parser.

    As to that I already found a solution (written in my previous post), but the resulting XML is not pretty-printed, but garbled. That is the because of the <xsl:text> element which confuses the parser I use, xsltproc. (I already mailed libxslt developers about this issue.)

    The solution you propose is not necessary. What would really help is a workaround without any <xsl:text> element. Unless the libxslt developers suggest a workaround or admit and fix a bug, I'm afraid I'll have to introduce that problematic line by sed...
    What is it that makes DocBook accept &copy and not xsltproc? If it is some kind of entity declaration, you can perhaps include the same declaration in the style sheet.

    You did write "bogus", so at least I thought you wanted that string as literal text for the end user to see.

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

    Re: XSLT help please

    Quote Originally Posted by Arndt View Post
    What is it that makes DocBook accept &copy and not xsltproc? If it is some kind of entity declaration, you can perhaps include the same declaration in the style sheet.

    You did write "bogus", so at least I thought you wanted that string as literal text for the end user to see.
    Yes, I want literal "&some-bogus-name;" to appear in the output XML (which in turn is an input for DocBook).

    However, such entity is never explicitly declared in DocBook. If it were, I'd just copy the declaration to my XSL stylesheet. DocBook simply tries to find a file with matching name and then includes its content. That's why I wrote it's an "include link".

    But I already solved this part and now I'm facing a well-formed but garbled XML output.
    בראשית ברא אלהים את השמים ואת הארץ׃

  8. #8
    Join Date
    Jul 2008
    Beans
    1,491

    Re: XSLT help please

    What are we looking at?

    If you want to XSLT *produce* "&copy;" you output "&amp;copy;". Doesn't have to be done through <xsl:text>, could be part of anything which emits PCDATA or attribute values.

    If you want a generic XML parser to *read* &copy; for use with XSLT this is not going to work because copy is an entity name not defined in the XML spec. You'd have to grab the Unicode code point, or just copy-paste ©. (Type: Alt-Gr + C on a keyboard using US Intl with Alt-Gr dead keys layout.)

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

    Re: XSLT help please

    Quote Originally Posted by Reiger View Post
    What are we looking at?

    If you want to XSLT *produce* "&copy;" you output "&amp;copy;". Doesn't have to be done through <xsl:text>, could be part of anything which emits PCDATA or attribute values.
    Can you perhaps give an example? I tried it myself, and when I put
    Code:
    &amp;some-bogus-name;
    it stays like that after XSLT, which is not what I want...
    בראשית ברא אלהים את השמים ואת הארץ׃

  10. #10
    Join Date
    Jul 2008
    Beans
    1,491

    Re: XSLT help please

    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.

Page 1 of 2 12 LastLast

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
  •