Help with XSL Document required

I

IanK

I have a file called product.xml as follows:

<products>
<product name="Maxi-ISA" friendlyname="Isa" />
<product name="PEP" friendlyname="Personal Equity Plan" />
<product name="General" friendlyname="General account" />
<product name="Pension" friendlyname="Pension drawdown" />
</products>

This is a file that maps product names (the "name" field) onto
user-friendly names (friendlyname) that can be used in client
documentation. I have the following code in my XSL function file that
tries to reference it. It is not working - what am I doing wrong?

<xsl:key name="product_name" match="product" use="@name"/>
<xsl:variable name="products" select="document('product.xml')"/>
<xsl:template name="nucleus_friendly_productname">
<xsl:param name="product_name_in"/>
<xsl:for-each select="document('products.xml')">
<xsl:variable name="product" select="key('product_name',
$product_name_in)"/>
<xsl:value-of select="$product/@friendlyname"/>
</xsl:for-each>
</xsl:template>
 
W

Warrell

Hi Ian,

This achieves what I think you want.

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

<xsl:key name="product_name" match="product" use="@name"/>

<xsl:template match="/products">
<xsl:call-template name="nucleus_friendly_productname"><xsl:with-param
name="product_name_in" select="'General'"/></xsl:call-template>
</xsl:template>

<xsl:template name="nucleus_friendly_productname">
<xsl:param name="product_name_in"/>

<xsl:value-of
select="key('product_name',$product_name_in)/@friendlyname"/>

</xsl:template>

</xsl:stylesheet>

tested using file product.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="get.xsl"?>
<products>
<product name="Maxi-ISA" friendlyname="Isa" />
<product name="PEP" friendlyname="Personal Equity Plan" />
<product name="General" friendlyname="General account" />
<product name="Pension" friendlyname="Pension drawdown" />
</products>

Of course the document context is already that of the product.xml document.

Hope this helps you,

Warrell
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top