Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 18th, 2006, 12:45 PM
IanK
Guest
 
Posts: n/a
Default Help with XSL Document required

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>

  #2  
Old December 19th, 2006, 10:15 AM
Warrell
Guest
 
Posts: n/a
Default Re: Help with XSL Document required

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


"IanK" <iankiddcroftamie@yahoo.co.ukwrote in message
news:1166445479.135229.136460@n67g2000cwd.googlegr oups.com...
Quote:
>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>
>

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles