[
Lists Home |
Date Index |
Thread Index
]
- From: "Thomas B. Passin" <tpassin@home.com>
- To: xml-dev@lists.xml.org
- Date: Wed, 18 Oct 2000 12:17:42 -0400
José Manuel Beas asks a significant question about xslt
(reproduced after this response) -
So as as I know, there are two ways to do this.
1) Use the Saxon xslt processor so you can use its
"evaluate()" extension function to evaluate your path
statement as a node set specification (see Michael Kay's
book "XSLT Programmer's Reference", p 649). Or,
2) Write a stylesheet to create a stylesheet that does what
you want, then run the second stylesheet.
I think that xslt SHOULD add an evaluate function, and right
away, too!
Here's a working ( I tried it and got the result you say you
want) version of your styleshseet, using the Saxon
"evaluate()" approach:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon">
<!--====== Note the saxon namespace! =========-->
<!--====== This part is unchanged ========-->
<xsl:template match="part">
<H1><xsl:value-of select="@name"/></H1>
<xsl:variable name="OBJECTNAME" select="class"/>
<xsl:variable name="QUERYSTRING" select="query"/>
<xsl:variable name="FILENAME"
select="document('master.xml')//object[@name =
$OBJECTNAME]/@href"/>
objectname = <xsl:value-of select="$OBJECTNAME"/><BR/>
filename = <xsl:value-of select="$FILENAME"/><BR/>
query = <xsl:value-of select="$QUERYSTRING"/><BR/>
<!--===============================-->
<!--==== use for-each to set the current node to the foreign
document ===-->
<xsl:for-each select="document($FILENAME)">
<!--==== Build the query string and evaluate it ======-->
<xsl:variable name="path"
select="saxon:evaluate(concat('//',$QUERYSTRING))"/>
<PRE>
<!--=== The evaluated path contains your data =====-->
<xsl:value-of select="$path"/>
</PRE>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Enjoy!
Tom Passin
>
> We have an xml file with a catalogue of parts, but their
descriptions
> are kept in a different xml file (this file depends on the
class of
> the part).
>
> These is the file:
>
> "parts.xml"
> ------------
> <parts>
> <part name="BigSquare">
> <class>square</class>
> <query>square[@id = '001']/color</query>
> </part>
> <part name="SmallCylinder">
> <class>cylinder</class>
> <query>cylinder[@id = '001']/color</query>
> </part>
> </parts>
> -----------
>
> I am transforming it into HTML with an XSLT by matching
the "part"
> template.
>
> "process.xslt"
> -----------
> <xsl:template match="part">
> <H1><xsl:value-of select="@name"/></H1>
> <xsl:variable name="OBJECTNAME" select="class"/>
> <xsl:variable name="QUERYSTRING" select="query"/>
> <xsl:variable name="FILENAME"
select="document('master.xml')//object
> [@name = $OBJECTNAME]/@href"/>
> objectname = <xsl:value-of select="$OBJECTNAME"/><BR/>
> filename = <xsl:value-of select="$FILENAME"/><BR/>
> query = <xsl:value-of select="$QUERYSTRING"/><BR/>
> <PRE>
> <xsl:value-of
select="document($FILENAME)//$QUERYSTRING"/>
> </PRE>
> </xsl:template>
> -----------
>
> What I am doing is to look for the filename corresponding
to each
> part "class" (into "master.xml") and then apply the
"query" to that
> xml file.
>
> But it doesn't work. I get the following error:
>
> oracle.xml.parser.v2.XSLException: XSL-1013: Error in
> expression: 'document($FILENAME)//$QUERYSTRING'.
>
>
> The rest of the files used are:
>
> "master.xml"
> ------------
> <master>
> <objects>
> <object name="square" href="squares.xml"/>
> <object name="cylinder" href="cylinders.xml"/>
> </objects>
> </master>
> ------------
> "squares.xml"
> ------------
> <squares>
> <square id="001">
> <color>Black</color>
> <size>big</size>
> </square>
> <square id="002">
> <color>Blue</color>
> <size>small</size>
> </square>
> </squares>
> -----------
>
> It's curious, but when I replace
> <xsl:value-of
select="document($FILENAME)//$QUERYSTRING"/>
> by (for example)
> <xsl:value-of select="document($FILENAME)//square[@id
> = '001']/color"/>
> I get the following:
> -----
> <PRE>
> Black
> </PRE>
> -----
>
> Which is EXACTLY what I am trying to obtain.
>
> Any ideas???
>
|