Entity references in attributes with xsl

Discussion in 'XML' started by Christoph Niemann, Aug 24, 2004.

  1. Hello,

    I want to output an element with an attribute. The attribute's value
    shall contain a entity reference. Is that possible at all?

    I use this source-XML and xsl-stylesheet:

    [-------------xml-source-----------------]

    <?xml version="1.0" encoding="utf-8"?>

    <slideshow>
    <slide name="01_welcome">
    <p>This is a test!</p>
    </slide>
    </slideshow>


    [-----------xsl-stylesheet---------------]

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:eek:utput method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    indent="yes"
    encoding="utf-8"/>

    <xsl:template match="/">
    <xsl:element name="html">
    <xsl:element name="head"/>
    <xsl:element name="body">
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:element>
    </xsl:template>


    <xsl:template match="slide">
    <!-- This works as expected. Output is:
    <p>&foo;</p>
    -->
    <xsl:element name="p">
    <xsl:text disable-output-escaping="yes">&amp;foo;</xsl:text>
    </xsl:element>

    <!-- This, however, doesn't. Output is:
    <img src="&amp;foo; />
    -->
    <xsl:element name="img">
    <xsl:attribute name="src">
    <xsl:text disable-output-escaping="yes">&amp;foo;</xsl:text>
    </xsl:attribute>
    </xsl:element>
    </xsl:template>

    </xsl:stylesheet>


    Now, xsltproc as well as saxon do escape the &amp; within the attribute
    value. Is that the intended behaviour? If so, how so I put an entity
    reference in an attribute value?

    Thanks in advance,

    Christoph
     
    Christoph Niemann, Aug 24, 2004
    #1
    1. Advertisements

  2. Christoph Niemann wrote:


    > I want to output an element with an attribute. The attribute's value
    > shall contain a entity reference. Is that possible at all?


    > Now, xsltproc as well as saxon do escape the &amp; within the attribute
    > value. Is that the intended behaviour? If so, how so I put an entity
    > reference in an attribute value?


    Saxon has an extension function:
    http://saxon.sourceforge.net/saxon6.5.3/extensions.html#saxon:entity-ref
    which might solve that (I haven't tried).

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 24, 2004
    #2
    1. Advertisements

  3. Christoph Niemann

    Imiro Guest

    Hi,

    could it be question of using '%' -sign instead of '&':


    <xsl:element name="img">
    <xsl:attribute name="src">
    <xsl:text disable-output-escaping="yes">%amp;foo;</xsl:text>
    </xsl:attribute>
    </xsl:element>

    Since maybe its like pcdata in first and cdata in second example? Not sure though ;)

    --Imiro
     
    Imiro, Aug 24, 2004
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    596
  2. David Madore
    Replies:
    1
    Views:
    651
    Richard Tobin
    Aug 28, 2003
  3. Replies:
    1
    Views:
    3,936
    A. Bolmarcich
    May 27, 2005
  4. Samuel van Laere

    Entity Name or Entity Number?

    Samuel van Laere, Feb 24, 2007, in forum: HTML
    Replies:
    4
    Views:
    2,474
    Jukka K. Korpela
    Feb 24, 2007
  5. Paquette.Jim
    Replies:
    2
    Views:
    587
    Oleg Tkachenko [MVP]
    Feb 6, 2007
  6. markla
    Replies:
    1
    Views:
    802
    Steven Cheng
    Oct 6, 2008
  7. Norm
    Replies:
    3
    Views:
    3,506
  8. ThatsIT.net.au

    Entity, problem with entity key

    ThatsIT.net.au, Sep 6, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    1,513
    ThatsIT.net.au
    Sep 7, 2009
Loading...