I don't think I was clear on one thing...the XSLT map goes in the XSLT like:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.o
xmlns:map="urn:schemas-rdc
exclude-result-prefixes="m
>
and then somewhere in your XSLT, perhaps in an imported one, you have a structure that looks like this:
<map:States>
<map:item key="AL">Alabama</map:item
<map:item key="AK">Alaska</map:item>
<map:item key="AZ">Arizona</map:item
<map:item key="AR">Arkansas</map:ite
<map:item key="CA">California</map:i
<map:item key="CO">Colorado</map:ite
[...]
<map:item key="WA">Washington</map:i
<map:item key="WV">West Virginia</map:item>
<map:item key="WI">Wisconsin</map:it
<map:item key="WY">Wyoming</map:item
</map:States>
</xsl:stylesheet>
The namespace at the beginning of the XSLT is required.
Main Topics
Browse All Topics





by: rdcproPosted on 2006-02-10 at 15:55:59ID: 15928086
To answer the first part, pre-compile your XSLT, and cache it. In ASP (but using javascript...):
rdcpro/sni ppets/cach ingtemplat es/
ThreadedDO MDocument" );
ThreadedDO MDocument. 4.0");
> > m> tem> m> tem> em> >
tylesheet/ map:States /map:item[ @key = current()/State]" />
tylesheet/ map:States /map:item" > of select="."/></option>
]">
http://rdcpro.com/Members/
That example shows MSXML 3.0, but if you're using MSXML 4.0, you'll get even better performance, because of the changes they made to it's threading model. Change all the reference to .4.0 like:
var xslDoc = new ActiveXObject("Msxml2.Free
becomes:
var xslDoc = new ActiveXObject("Msxml2.Free
To answer your second question, it sounds like this is a somewhat static fragment of XML, right? In that case, I use a technique that I like to refer to as an XSLT map. This allows me to access XML trees without having to use msxsl:node-set(). It works like this:
<!-- A useful technique for adding a lookup table to a transformation.
Of course, these could be added as parameters, too,
but it's often more useful to have them here -->
<map:States>
<map:item key="AL">Alabama</map:item
<map:item key="AK">Alaska</map:item>
<map:item key="AZ">Arizona</map:item
<map:item key="AR">Arkansas</map:ite
<map:item key="CA">California</map:i
<map:item key="CO">Colorado</map:ite
[...]
<map:item key="WA">Washington</map:i
<map:item key="WV">West Virginia</map:item>
<map:item key="WI">Wisconsin</map:it
<map:item key="WY">Wyoming</map:item
</map:States>
Then if I have an input XML node like <State>WA</State>, I can swap it for the value "Washington" with this:
<xsl:value-of select="document('')/xsl:s
You can iterate over these as node sets, too, if you wish. To create a select box, I'd use:
<xsl:for-each select="document('')/xsl:s
<option id="optStateSelect" value="{@key}"><xsl:value-
</xsl:for-each>
Now, if that stuff is dynamically set from the XML, then you have to use the msxsl:node-set.
If all you want to do is output one thing over another, depending on the value of a parameter (the adminstrator param), you can do it like:
<xsl:param name="pIsAdmin" select="boolean(false)"/>
<xsl:for-each select="SomeNode[$pIsAdmin
do some stuff here
</xsl:for-each>
That way, the for-each is executed only if the IsAdmin variable or parameter is set to true. The trick is to remember that the value in the predicate (the square brackets) needs to evaluate to true or false, but it doesn't in any way need to be related to the node you're iterating over.
Regards,
Mike Sharp