Using value-of within double quotes??

Discussion in 'XML' started by bissatch@yahoo.co.uk, Mar 1, 2007.

  1. Guest

    Hi,

    I have a an XML file:

    <xml...
    <store>
    <book>
    <title>Darkness at Noon</title>
    <price>12.99</price>
    <url>http://www.amazon.com/...</url>
    </book>
    .
    .
    .
    </store>

    I am trying to outout it using the following segment in my XSL file:

    <xsl:for-each select="store/book">
    <p><strong><value-of select="title" /></strong></p>
    <p>&pound;<value-of select="price" /></p>
    <p><a href="<value-of select="url" />">Buy book</a></p>
    </xsl:for-each>

    Now I was certain that this would fail as it is not valid XML but I
    have no idea how I would add a value to a HTML attribute (within
    double quotes). Obviously Im going about this the wrong way but could
    someone please tell me the correct method for this. Thanks

    Burnsy
    , Mar 1, 2007
    #1
    1. Advertising

  2. Guest

    Figured it out (eventually)

    <xsl:for-each select="store/book">
    <p><strong><value-of select="title" /></strong></p>
    <p>&pound;<value-of select="price" /></p>
    <p><a href="{url}">Buy book</a></p>
    </xsl:for-each>


    or use xsl:attribute but havent yet tried that one.
    , Mar 1, 2007
    #2
    1. Advertising

  3. wrote:
    > <p><a href="{url}">Buy book</a></p>


    Yep; that's known as an Attribute Value Template (AVT), and is the
    simplest way to generate an attribute with a known name.

    > or use xsl:attribute but havent yet tried that one.


    More often used when you need to programmatically generate the
    attribute's name, or when you need fancier logic in setting its value
    than an AVT can support:

    <p><a><xsl:attribute name="href" select="url"/>Buy book</a></p>
    or

    <p><a><xsl:attribute name="href"><xsl:value-of
    select="url"/></xsl:attribute>Buy book</a></p>

    or, for stylesheet readability reasons:
    <p><a>
    <xsl:attribute name="href"/>
    <xsl:value-of select="url"/>
    </xsl:attribute>
    <xsl:text>Buy book</xsl:text>
    </a></p>

    .... or any of the equivalents thereof. (XSLT being a programming
    language, there is usually more than one way to achieve a given result.)



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Mar 1, 2007
    #3
  4. Joe Kesselman wrote:

    > More often used when you need to programmatically generate the
    > attribute's name, or when you need fancier logic in setting its value
    > than an AVT can support:
    >
    > <p><a><xsl:attribute name="href" select="url"/>Buy book</a></p>


    But xsl:attribute in XSLT 1.0 does not have a select attribute
    <http://www.w3.org/TR/xslt#creating-attributes>
    it is a bit dangerous to show that example above without mentioning it
    is only supported in XSLT 2.0
    <http://www.w3.org/TR/xslt20/#creating-attributes>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 1, 2007
    #4
  5. Martin Honnen wrote:
    > But xsl:attribute in XSLT 1.0 does not have a select attribute


    Whups. You're right, very sloppy of me. I did illustrate the
    value-as-content solution as well; that does work in 1.0.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Mar 1, 2007
    #5
    1. Advertising

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. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,843
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    13,627
    Oisin
    Mar 24, 2006
  3. Sydex
    Replies:
    12
    Views:
    6,472
    Victor Bazarov
    Feb 17, 2005
  4. DennBen
    Replies:
    6
    Views:
    1,855
    Jukka K. Korpela
    Mar 29, 2007
  5. jOhn
    Replies:
    1
    Views:
    219
    Phlip
    Jan 29, 2008
Loading...

Share This Page