This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Assigning a dynamic value of href in a stylesheet PI


You can use <xsl:value-of> inside <xsl:processing-instruction>

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com 

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com 
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of 
> Roger L. Costello
> Sent: 25 July 2002 17:07
> To: xsl-list@lists.mulberrytech.com; Costello,Roger L.
> Subject: [xsl] Assigning a dynamic value of href in a stylesheet PI
> 
> 
> 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
> 
> 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]