xml editor

   XML Editor
   XML Author
      DITA Editor
      DocBook Editor
      TEI Editor
      XHTML Editor
      Schema Editor
      XML Schema Editor
      RelaxNG Editor
   XQuery
   SVN Client
      Office Open XML
      XSL:FO Editor
      SVG Editor
      WSDL Editor
Supported platforms
Compatible with Windows7 & Mac OS X Snow Leopard
Ready for
data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Assigning a dynamic value of href in a stylesheet PI


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
Keywords
xml
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2009 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>® XML Editor