[Home] [By Thread] [By Date] [Recent Entries]
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
|

Cart



