|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Key and document() problem ?
At 2008-10-07 17:43 +0200, Emilise Victor wrote:
I would like to construct a key based on a different document, but I saw that is was not going to work. So I'm going explain what I want to do, since now I have no idea how it could be done. You don't explain why you don't have the for-each loop ... and you don't explain your rationale for error codes. And you don't indicate if you are using XSLT 1 or XSLT 2. So I'm not sure if I can help. I don't know if it's clear. I don't even see clearly myself how I could achieve this. The example below shows the access to two different documents producing a report of the comparison of information. I'm not sure if it will help you or not. I'm not sure why you weren't using variables in your example, so in the below I have code without and then with variables, and I'm using XSLT 1 assuming you are since you didn't mention XSLT 2. BTW, you don't have to worry about calling the document() function multiple times because the processor is supposed to fetch the document only once. I hope this helps. . . . . . . . . . . Ken
T:\ftemp>type monitor.xml
<monitor id="45995">
<site>
<test id="36">
<request id="1">
<data id="4" value="2394"/>
</request>
<request id="2">
<data id="4" value="1969"/>
</request>
<request id="3">
<data id="4" value="5451"/>
</request>
</test>
</site>
</monitor>T:\ftemp>call xslt victor1.xsl victor1.xsl victor1.out T:\ftemp>type victor1.out Step 1: (1) 2394 NO TIMEOUT [4000] Step 2: (2) 7420 NO TIMEOUT [9000] Step 3: (2) 7420 TIMEOUT [6000] T:\ftemp>call xslt victor2.xsl victor2.xsl victor2.out T:\ftemp>type victor2.out Step 1: (1) 2394 NO TIMEOUT [4000] Step 2: (2) 7420 NO TIMEOUT [9000] Step 3: (2) 7420 TIMEOUT [6000] T:\ftemp>type victor1.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output method="text"/> <xsl:variable name="job">job.xml</xsl:variable> <xsl:variable name="monitor">monitor.xml</xsl:variable> <xsl:template match="/"> <xsl:for-each select="document($job)/job/universe/monitor/step"> <xsl:text/>Step <xsl:value-of select="@id"/>: (<xsl:text/> <xsl:value-of select="count(document($monitor)/monitor/site/test/request [@id=current()/request/@id])"/> <xsl:text>) </xsl:text> <xsl:value-of select="sum(document($monitor)/monitor/site/test/request [@id=current()/request/@id]/data/@value)"/> <xsl:text> </xsl:text> <xsl:choose> <xsl:when test="sum(document($monitor)/monitor/site/test/request [@id=current()/request/@id]/data/@value) > @timeout"> <xsl:text>TIMEOUT</xsl:text> </xsl:when> <xsl:otherwise>NO TIMEOUT</xsl:otherwise> </xsl:choose> <xsl:text/> [<xsl:value-of select="@timeout"/><xsl:text>] </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet>
T:\ftemp>type victor2.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output method="text"/> <xsl:variable name="job">job.xml</xsl:variable> <xsl:variable name="monitor">monitor.xml</xsl:variable> <xsl:template match="/">
<xsl:for-each select="document($job)/job/universe/monitor/step">
<xsl:text/>Step <xsl:value-of select="@id"/>: (<xsl:text/>
<xsl:variable name="test-requests"
select="document($monitor)/monitor/site/test/request
[@id=current()/request/@id]"/>
<xsl:value-of select="count($test-requests)"/>
<xsl:text>) </xsl:text>
<xsl:variable name="sum-test-requests"
select="sum($test-requests/data/@value)"/>
<xsl:value-of select="$sum-test-requests"/>
<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="$sum-test-requests > @timeout">
<xsl:text>TIMEOUT</xsl:text>
</xsl:when>
<xsl:otherwise>NO TIMEOUT</xsl:otherwise>
</xsl:choose>
<xsl:text/> [<xsl:value-of select="@timeout"/><xsl:text>]
</xsl:text>
</xsl:for-each>
</xsl:template></xsl:stylesheet> T:\ftemp>rem Done!
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








