[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Accessing array variable

Subject: Re: Accessing array variable
From: Goetz Bock <bock@xxxxxxxxxxx>
Date: Thu, 14 Jun 2001 01:53:02 +0200
xslt array variable
On Wed, Jun 13 '01 at 11:52, Andy Srinivasan wrote:
> Still the value is blank
Here you go, this is tested to work with saxon.

Dummy input XML (test.xml):
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!-- filename:      test.xml 
     created on:    2001 Jun 14 01:44:46 +0200 (CEST)
     last modified: 2001 Jun 14 01:44:57 +0200 (CEST)
     (c) 2001 by Goetz Bock <bock@xxxxxxxxxxx>
     -->
<test />
----------------------------------------------------------------------

Demo XSLT (test.xsl):
----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!-- filename:      test.xsl 
     created on:    2001 Jun 14 01:35:21 +0200 (CEST)
     last modified: 2001 Jun 14 01:47:18 +0200 (CEST)
     (c) 2001 by Goetz Bock <bock@xxxxxxxxxxx>
     -->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:local="data local to this file"
               version='1.0'>
               
<xsl:output method="text" />

<local:benefit>
    <local:period ID='12M'>1</local:period>
    <local:period ID='18M'>2</local:period>
    <local:period ID='24M'>3</local:period>
    <local:period ID='2Y' >4</local:period>
    <local:period ID='5Y' >5</local:period>
</local:benefit>

<xsl:template match="/">
  <xsl:text>First we try to find the value for "12M" (should be 1): </xsl:text>
  <xsl:value-of select="document('')//local:benefit/local:period[@ID='12M']"/>
  <xsl:text>&#xA;Now we define a variable $BP to be "18M".</xsl:text>
  <xsl:variable name="BP">18M</xsl:variable>
  <xsl:text>&#xA;$BP is defined as: </xsl:text>
  <xsl:value-of select="$BP" />
  <xsl:text>&#xA;Now we try to find the value for $BP (should be 2): </xsl:text>
  <xsl:value-of select="document('')//local:benefit/local:period[@ID=$BP]"/>
  <xsl:text>&#xA;</xsl:text>
</xsl:template>
    
</xsl:transform>
----------------------------------------------------------------------

You run it like this:
----------------------------------------------------------------------
~/temp > saxon test.xml test.xsl                                   
First we try to find the value for "12M" (should be 1): 1
Now we define a variable $BP to be "18M".
$BP is defined as: 18M
Now we try to find the value for $BP (should be 2): 2
----------------------------------------------------------------------
 
Hope you can write your complete XSL-T now.

    Goetz.

Attachment: pgp00009.pgp
Description: PGP signature

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.