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

Re: .properties file equivalent facility in XSL

Subject: Re: .properties file equivalent facility in XSL
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Mon, 01 Apr 2002 12:36:41 +0200
xsl properties file
Shaik Zulfakhar Ali wrote:
Is there any facility in XSL by which we can store name and value
parameters.
You can put name-value pairs into an XML structure and
access them using the document() function.

For example:
<?xml version="1.0"?>
<properties>
  <property><name>foo</name><value>Real Foo</value></property>
  <property><name>bar</name><value>Real Bar</value></property>
</properties>

somewhere in the XSL:
  <xsl:value-of select="document('prop.xml')/properties/property[name=$selected-name]/value"/>

You can put this data also directly into the XSL file.
The data appears as child elements of the xsl:stylesheet
element, you also have to define your own namespace so the
processor can tell your data from its instructions. The
following example declares a prefix "data" for this purpose.
The stylesheet file is accessed by passing an empty string
as URI to the document() function:

<xsl:stylesheet version="1.0" xmlns:xsl="http://..."
  xmlns:data="some.uri.you.control"/>
  <data:properties>
    <property><name>foo</name><value>Real Foo</value></property>
    <property><name>bar</name><value>Real Bar</value></property>
  </data:properties>
   ...
    <xsl:value-of select="document('')/data:properties/property[name=$selected-name]/value"/>

It may be more convenient to assign the node set to a variable,
especially if you access them often.

  <xsl:variable name="properties" select=""document('prop.xml')/properties/property"/>
   ...
    <xsl:value-of select="$properties[name=$selected-name]/value"/>

If you have a lot of properties and you access them often,
using a key for retrieving the values is a way to improve
performance.
Because keys work only for the current document, you have
to use a trick to switch to the document containing the
properties. Using a dummy xsl:for-each does this:

  <xsl:key name="property" match="property" use="name"/>
  ...
    <xsl:for-each select="$properties"/>
      <xsl:value-of select="key('property',$selected-name)/value"/>
    </xsl:for-each>

HTH
J.Pietschmann


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



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-2007 All Rights Reserved.