Re: [xsl] xsl/xml question

Subject: Re: [xsl] xsl/xml question
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Mon, 03 Mar 2003 10:27:30 +0000
From: "Wendy Ang" <wendy@xxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] xsl/xml question
Date: Mon, 3 Mar 2003 18:17:20 -0800

Dear List,

I have the following XML Data format:

<ProductList>
	<Product>
		<ProductID>111</ProductID>
		<ProductName>abc</ProductName>
		...
	</Product>
</ProductList>

and I need to transform it with the corresponding XSL template using the
transformNode of MicrosoftXMLDOM

the XSL Template goes:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

<xsl:template match="/">
    <table border="2">
      <xsl:for-each select="/ProductList/Product">
	      <tr>
		<td>
		    Product ID: <xsl:value-of select="ProductID"/><br/>
		    Product Name: <a href="$ProductID"><xsl:value-of
select="ProductName"/></a><br/>
		    Product Code: <xsl:value-of
select="ProductCode"/><br/>
		    Description: <xsl:value-of
select="Description"/><br/>
		    Picture: <xsl:value-of select="Picture"/><br/>
		    <xsl:value-of select="Active"/><br/>
		    <xsl:value-of select="bNew"/><br/>
		    <xsl:value-of select="Special"/><br/>
		    <xsl:value-of select="AllowWriteIn"/><br/>
		    <xsl:value-of select="WriteInText"/><br/>
		    <xsl:value-of select="ListPrice"/><br/>
		    <xsl:value-of select="SellingPrice"/><br/>
		    <xsl:value-of select="PricePerUnit"/><br/>
		    <xsl:value-of select="MemberPrice"/><br/>
		    <xsl:value-of select="ActualCost"/><br/>
		    <xsl:value-of select="VolumePricing"/><br/>
		    <xsl:value-of select="VolumeQuantity"/><br/>
		    <xsl:value-of select="VolumePrice"/><br/>
		    <xsl:value-of select="VolumeEvenQuantity"/><br/>
		    <xsl:value-of
select="ApplyQuantitiesOverVolume"/><br/>
		    <xsl:value-of select="SupplierID"/><br/>
		    <xsl:value-of select="ExternalURL"/><br/>
		    <xsl:value-of select="ExtraInfoOffer"/><br/>
		    <xsl:value-of select="ExtraInfoLocation"/><br/>
		    <xsl:value-of select="Status"/><br/></td>
	      </tr>
      </xsl:for-each>
    </table>
</xsl:template>
</xsl:stylesheet>



now, if you can see this part:

    Product Name: <a href="$ProductID"><xsl:value-of
select="ProductName"/></a><br/>
		    Product Code: <xsl:value-of
select="ProductCode"/><br/>

I'm trying to get the value of ProductID and assign it to the "href"
attribute of the element <a>... anyone knows how to solve this problem?
Thanks in advance :)

Firstly aviod using the antiquated working draft transformation language indicated by:
xmlns:xsl="http://www.w3.org/TR/WD-xsl";
change this to:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
if you are using version 3 parser or better and set the selectionLanguage to "XPath". See help docs for examples.
Secondly what you need is called an Attribute Value Template. Change:
<a href="$ProductID">
to
<a href="{$ProductID}">
anything in {} will be evaluated as an XPath expression.


Joe

_________________________________________________________________
Stay in touch with MSN Messenger http://messenger.msn.co.uk


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread