Evaluate a string to a node set?

Subject: Evaluate a string to a node set?
From: "Hitchman, Andrew" <Andrew.Hitchman@xxxxxxxxxxxxx>
Date: Thu, 3 Aug 2000 10:39:40 +0200
Hi,

To allow our HTML designers to concentrate on writing HTML with existing
tools 
(like Dreamweaver) we are attempting to separate HTML presentation layout
from 
XML data.

So, out HTML designer would create team.html as below and use the tag
<xdata> 
to reference the XML data provided by our application. The stylesheet uses
the XML 
document as the root and includes the HTML. On matching the <xdata> element
in 
the HTML document the XSLT processor substitutes the value from the XML
document 
and for a named node this works fine (actually in the example below it works
only by 
virtue of the fact that the first name element is the team name). 

See end of message for an example of what I mean.

But what we really need to be able to do is specify a path in the xdata
select attribute, 
e.g.

   <xdata select="team/notes">
or 
   <xdata select="driver[1]/name">
or
   <xdata select="driver[name = "Schumacher"]/date-of-birth">

and whilst

   <xsl:template match="xdata" mode="presentation">
      <xsl:variable name="this" select="."/>
      <xsl:value-of select="$data//*[name(.) = $this/@select]/>
   </xsl:template>

will work where @select is limited to a node name, there doesn't seem to be
a way to match 
a path represented as a string, for example (fictionally):

   <xsl:value-of select="$data//*[. =
node-set-matching-string($this/@select)]/> 

Is there something I'm missing?  (FYI, I'm using Xalan).

I know that this whole approach seems a bit daft given that XSLT can convert
the XML 
document into the HTML shown without any problem at all, but this would mean
losing 
the use of our visual development tools for creating the HTML. And moreover
this radical 
split of presentation and data seems much more robust and maintainable than
direct 
transformation from XML to HTML.

Cheers,

Andy Hitchman.


Example:
============
team.html
-------------------------
<html>
   <head>
      <title>View Team <xdata select="name"/></title>
   </head>
   <body>
      <h1>Team <xdata select="name"/></h1>
      <xdata select="notes"/>
   </body>
</html>

team.xml
--------------------------
<team>
   <name>Ferrari</name>
   <notes>Bla-bla-bla...</notes>
   <driver>
      <name>Schumacher</name>
      <date-of-birth>1969-01-03</date-of-birth>
   </driver>
   <driver>
      <name>Irvine</name>
      <date-of-birth>1965-11-10</date-of-birth>
   </driver>
</team>


fragment of team.xsl (with team.xml at the root document)
---------------------------
...
<xsl:variable name="data" select="/"/>
<xsl:variable name="presentation" select="document("team.html")"/>

<xsl:template match="/">
   <xsl:apply-templates/>
<xsl:template>

<xsl:template match="team">
   <!-- Pass thru the html presentation -->
   <xsl:apply-templates select="$presentation" mode="presentation"/>
</xsl:template>

<!-- For xdata in presentation html, insert the value from the xml document.
-->
<xsl:template match="xdata" mode="presentation">
   <xsl:variable name="this" select="."/>
   <xsl:value-of select="$data//*[name(.) = $this/@select]/>
</xsl:template>

<!-- For presentation html, pass thru unchanged. -->
<xsl:template match="@*|*" mode="presentation">
   <xsl:copy>
      <xsl:apply-templates select="@*|node()" mode="presentation"/>
   </xsl:copy>
</xsl:template>
...



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


Current Thread