Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using value-of within double quotes??

Reply
Thread Tools

Using value-of within double quotes??

 
 
bissatch@yahoo.co.uk
Guest
Posts: n/a
 
      03-01-2007
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

 
Reply With Quote
 
 
 
 
bissatch@yahoo.co.uk
Guest
Posts: n/a
 
      03-01-2007
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.

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      03-01-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      03-01-2007
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/
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      03-01-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
from List <double> to double[] Web learner ASP .Net 3 04-26-2006 05:26 PM
Using values within arrays within a hash to gsub into an input word... Abe Ruby 2 04-15-2006 08:16 PM
Should I be concerned about buying DVD18s (Double-sided, double-layered) The Man With No Name DVD Video 3 02-04-2006 01:45 AM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
Double double display display problem problem Tom Accuosti Firefox 3 09-27-2004 10:02 PM



Advertisments