Subject: Re: [xsl] .properties file equivalent facility in XSL From: "J.Pietschmann" <j3322ptm@xxxxxxxx> Date: Mon, 01 Apr 2002 12:36:41 +0200 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] .properties file equivalent f, Shaik Zulfakhar Ali | Thread | [xsl] unable to pass parameters fro, Aseef Jamaluddin |
[xsl] .properties file equivalent f, Shaik Zulfakhar Ali | Date | [xsl] unable to pass parameters fro, Aseef Jamaluddin |
Month |