Subject: [xsl] Assigning a dynamic value of href in a stylesheet PI From: "Roger L. Costello" <costello@xxxxxxxxx> Date: Thu, 25 Jul 2002 12:07:26 -0400 |
Hi Folks, I have a stylesheet which outputs an XML document, containing a stylesheet processing instruction (PI). I would like for the PI to be customized to the client. (I have a different stylesheet for each client.) For example, if the client is Internet Explorer, then the PI should be: <?xml-stylesheet href="MSIE-parts-styler.xsl" type="text/xsl"?> If the client is Netscape, then the PI should be: <?xml-stylesheet href="Netscape-parts-styler.xsl" type="text/xsl"?> And so forth. I pass into my stylesheet a parameter, client, which indicates who the client is. Since the list of clients will grow over time I don't want to have to hard code into the stylesheet all the clients. That is, I don't want to do this: <xsl:template match="/"> <xsl:choose> <xsl:when test="$client='MSIE'"> <xsl:processing-instruction name="xml-stylesheet"> <xsl:text> href="MSIE-part-styler.xsl" type="text/xsl" </xsl:text> </xsl:processing-instruction> </xsl:when> <xsl:when test="$client='Netscape'"> <xsl:processing-instruction name="xml-stylesheet"> <xsl:text> href="Netscape-part-styler.xsl" type="text/xsl" </xsl:text> </xsl:processing-instruction> </xsl:when> </xsl:choose> </xsl:template> Ideally, I would like to do this: <xsl:template match="/"> <xsl:processing-instruction name="xml-stylesheet"> href="{concat($client, "-part-styler.xsl")} type="text/xsl" </xsl:processing-instruction> </xsl:template> Where client is the name of the parameter that is passed into the stylesheet. Alas, this later approach is not possible (because the contents of xsl:processing-instruction must be text). Does anyone have a good solution for this? That is, one that doesn't force me to add a new xsl:when clause every time a new type of client comes in. OFFTOPIC: Does anyone know how a HTTP header indicates that the client is Netscape (as opposed to IE)? The HTTP user-agent header field contains MSIE if the client is IE. If the client is Netscape there doesn't seem to be any way of identifying that the client is Netscape. Any ideas? Thanks! /Roger XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Adding variables to the d, Michael Kay | Thread | Re: [xsl] Assigning a dynamic value, G. Ken Holman |
RE: [xsl] Adding variables to the d, Michael Kay | Date | [xsl] ANN: XSLT Tools and Resources, Chuck White |
Month |