Re: DTD/xsl:import

Subject: Re: DTD/xsl:import
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 7 Nov 2000 09:57:34 +0000
Maulik,

> Also in the above <!ENTITY rootdir>, I would like to formulate the string
> dynamically from a XML file using the document() function. I am not having
> toomuch luck with that either. Any help. The sample XML for that is as
> follows:
>
> <MESSAGE>
>   <CONFIG>
>     <FILES>
>      <SERVER>sdangel03</SERVER>
>      <PATH>tms</PATH>
>     </FILES>
>     <SERVLET>
>         <SERVER>jjdamukaitis01</SERVER>
>         <PORT>7001</PORT>
>     </SERVLET>
>   </CONFIG>
> </MESSAGE>

You can't dynamically generate the string that is used in an ENTITY
definition.  However, you *can* do this if, instead of using an
ENTITY, you store the string as a global variable, and then refer to
it as such.

You can store the CONFIG element from (let's say) message.xml, in a
variable using the document() function to access the root node of the
document, and an XPath to access the CONFIG element from there:

<xsl:variable name="config"
              select="document('message.xml')/MESSAGE/CONFIG" />

Now, the base URL for the files can be generated by concatenating the
FILES/SERVER and FILES/PATH together, with a '/' separator and
prefixed with 'http://':

  concat('http://', $config/FILES/SERVER, '/', $config/FILES/PATH)

If you're only accessing this information once, then you could just
use that, but otherwise it's worth putting it in a variable:

<xsl:variable name="file-base-url"
              select="concat('http://', $config/FILES/SERVER, '/',
                             $config/FILES/PATH)" />

Then, you can include this variable within your XSLT, either using:

  <xsl:value-of select="$file-base-url" />

or, if you're within an attribute, using an attribute value template:

  {$file-base-url}

In your case, for example, you can do:

<xsl:template match="/">
  ...perform some code...
  <img src="{$file-base-url}/images/name.gif" />
  <xsl:apply-templates select="//Names/Name" >
    <xsl:sort select="FN" />
  </xsl:apply-templates>
</xsl:template>

I hope that this helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread
  • DTD/xsl:import
    • mxmodi - Mon, 6 Nov 2000 15:49:33 -0600
      • Mike Brown - Mon, 6 Nov 2000 16:41:42 -0700 (MST)
      • Jeni Tennison - Tue, 7 Nov 2000 09:57:34 +0000 <=