I suspect the problem is with your calls on position() inside the
predicate. I haven't worked through your logic enough to understand what
you expect position() to give you, but it certainly looks wrong. Perhaps
you want the position outside the predicate rather than inside it, in
which case assign it to a variable.
Michael Kay
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
Richard Patchet
Sent: 21 January 2004 23:46
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Inconsistent XPath Evaluation
I have a transform that cross-references an external file for
some data. The expressions were created by copying the long
expressions from the first for-each loop of the transform to
the second for-each loop and changing just the "parentcir_"
literal to "childcir_" in the latter xpaths. I am using Saxon
6.5.3 throughout.
I added some debugging displays between the "cmdId" attribute
and the "count" element unrelated to the original transform:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:opl="http://www.a4networks.com/schemas/opl"
version="1.1" exclude-result-prefixes="xsl opl">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:element name="btradeCollaborationReport">
<xsl:copy-of select="/btradeCollaboration/header"/>
<xsl:for-each
select="/btradeCollaboration/linkCmdList/linkCmd/link/parent[n
ot(itemId
!= '')]">
<xsl:element name="cmdStatus">
<xsl:attribute name="cmdId">
<xsl:value-of select="concat('parentcir_',
../../@cmdId, '-', position())"/>
</xsl:attribute>
<xsl:variable name="test"
select="concat('parentcir_', ../../@cmdId, '-', position())"/>
text:<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)quer
y-id = concat('parentcir_', current()/../../@cmdId, '-',
position())]/@query-id"/>:
var:<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)query-id =
$test]/@query-id"/>:
<xsl:element name="count">
<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)quer
y-id = concat('parentcir_', current()/../../@cmdId, '-',
position())]/Result/Row/tradeItem/updateCount"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
<xsl:for-each
select="/btradeCollaboration/linkCmdList/linkCmd/link/child[not(itemId
!= '')]">
<xsl:element name="cmdStatus">
<xsl:attribute name="cmdId">
<xsl:value-of select="concat('childcir_',
../../@cmdId, '-', position())"/>
</xsl:attribute>
<xsl:variable name="test"
select="concat('childcir_', ../../@cmdId, '-', position())"/>
text:<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)quer
y-id = concat('childcir_', current()/../../@cmdId, '-',
position())]/@query-id"/>:
var:<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)query-id =
$test]/@query-id"/>:
<xsl:element name="count">
<xsl:value-of
select="document('dbResultDoc.xml')/ResultSet/ResultList[(_at_)quer
y-id = concat('childcir_', current()/../../@cmdId, '-',
position())]/Result/Row/tradeItem/updateCount"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:transform>
The source XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="t_linkPrepareDBReport.xslt"?>
<btradeCollaboration force="true">
<header>
<username>rbat</username>
<transactionId>link2004-01-20T16:58:40-6:00</transactionId>
</header>
<linkCmdList>
<linkCmd cmdId="5" type="LINK">
<link>
<parent>
<catalogueItemReference>100444222010174442223333309840</catalo
gueItemRef
erence>
</parent>
<child>
<catalogueItemReference>000444219010034442223333309840</catalo
gueItemRef
erence>
</child>
</link>
</linkCmd>
<linkCmd cmdId="6" type="LINK">
<link>
<parent>
<catalogueItemReference>100444222011164442223333309840</catalo
gueItemRef
erence>
</parent>
<child>
<catalogueItemReference>000444219210014442223333309840</catalo
gueItemRef
erence>
</child>
</link>
</linkCmd>
</linkCmdList>
</btradeCollaboration>
The cross-reference file:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet resultLists="14"
correlation-id="link2004-01-20T16:58:40-6:00">
<ResultList results="1" query-id="parentcir_5-5">
<Result rows="1">
<Row cols="1">
<tradeItem>
<id>298</id>
<status>1</status>
<updateCount>0</updateCount>
</tradeItem>
</Row>
</Result>
</ResultList>
<ResultList results="1" query-id="parentcir_6-6">
<Result rows="1">
<Row cols="1">
<tradeItem>
<id>299</id>
<status>1</status>
<updateCount>0</updateCount>
</tradeItem>
</Row>
</Result>
</ResultList>
<ResultList results="1" query-id="childcir_5-1">
<Result rows="1">
<Row cols="1">
<tradeItem>
<id>294</id>
<status>1</status>
<updateCount>0</updateCount>
</tradeItem>
</Row>
</Result>
</ResultList>
<ResultList results="1" query-id="childcir_6-2">
<Result rows="1">
<Row cols="1">
<tradeItem>
<id>296</id>
<status>1</status>
<updateCount>0</updateCount>
</tradeItem>
</Row>
</Result>
</ResultList>
</ResultSet>
The output:
<?xml version="1.0" encoding="UTF-8"?> <btradeCollaborationReport>
<header>
<username>rbat</username>
<transactionId>link2004-01-20T16:58:40-6:00</transactionId>
</header>
<cmdStatus cmdId="parentcir_5-1">
text:parentcir_5-1:
var:parentcir_5-1:
<count>0</count>
</cmdStatus>
<cmdStatus cmdId="parentcir_6-2">
text:parentcir_6-2:
var:parentcir_6-2:
<count>0</count>
</cmdStatus>
<cmdStatus cmdId="childcir_5-1">
text::
var:childcir_5-1:
<count/>
</cmdStatus>
<cmdStatus cmdId="childcir_6-2">
text::
var:childcir_6-2:
<count/>
</cmdStatus>
</btradeCollaborationReport>
It makes no sense to me why the xpath expression works for
with "parentcir_" but not "childcir_" and that it works with
the concat() in a variable but not in the xpath.
What am I missing here?
Richard Patchet
bTrade, Inc.
2324 Gateway Drive
Irving, TX 75063
972-5802981
www.bTrade.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list