捕获的累加器上的 id()
id() on captured accumulator
我有一个存储某些 xs:ID 类型数据的累加器。我想使用 id() 函数引用它,最初我认为这可行。它确实如此,但只有当 `accumulator-after('acc')/id 函数被提供一个字符串文字时。如果传递了一个表达式(例如一个节点),该函数将 return 什么都没有。我测试了全局 id() 函数(关闭了流),它按预期工作。这是我的测试用例
XSD
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="urn:test" xmlns:ns1="urn:test">
<xsd:complexType name="IDHolder" abstract="false" mixed="true">
<xsd:attribute name="ObjectId" type="xsd:ID" use="required"/>
</xsd:complexType>
<xsd:element name="RootElement">
<xsd:complexType>
<xsd:sequence maxOccurs="1">
<xsd:element name="MiddleElement">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="ChildElement" type="ns1:IDHolder"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="ObjectId" type="xsd:IDREF" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:t="urn:test"
exclude-result-prefixes="xs math" version="3.0" expand-text="yes">
<xsl:mode streamable="yes" use-accumulators="#all"/>
<xsl:import-schema schema-location="issuereporo.xsd" namespace="urn:test"/>
<xsl:accumulator name="acc" as="node()?" initial-value="()" streamable="yes">
<xsl:accumulator-rule xmlns:saxon="http://saxon.sf.net/" match="t:MiddleElement" select="."
phase="end" saxon:capture="yes"/>
</xsl:accumulator>
<xsl:template match="t:RootElement">
<xsl:apply-templates />
<xsl:variable name="vAcc" select="accumulator-after('acc')"/>
Direct Access
{$vAcc/id('_1')}
Access via context node
<!--THIS IS WHAT DOESN'T WORK-->
{$vAcc/id(@ObjectId)}
Access via global
<!-- will only work when streaming is off -->
{id(@ObjectId)}
</xsl:template>
</xsl:stylesheet>
XML
<?xml version="1.0" encoding="UTF-8"?>
<RootElement xmlns="urn:test" ObjectId="_2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test file:/C:/Users/john/Documents/GitHub/streamatron-test/issuereporo.xsd">
<MiddleElement>
<ChildElement ObjectId="_1">C
</ChildElement>
<ChildElement ObjectId="_2">D
</ChildElement>
</MiddleElement>
</RootElement>
我想你想要 {$vAcc/id(current()/@ObjectId)}
而不是 {$vAcc/id(@ObjectId)}
。
我有一个存储某些 xs:ID 类型数据的累加器。我想使用 id() 函数引用它,最初我认为这可行。它确实如此,但只有当 `accumulator-after('acc')/id 函数被提供一个字符串文字时。如果传递了一个表达式(例如一个节点),该函数将 return 什么都没有。我测试了全局 id() 函数(关闭了流),它按预期工作。这是我的测试用例
XSD
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="urn:test" xmlns:ns1="urn:test">
<xsd:complexType name="IDHolder" abstract="false" mixed="true">
<xsd:attribute name="ObjectId" type="xsd:ID" use="required"/>
</xsd:complexType>
<xsd:element name="RootElement">
<xsd:complexType>
<xsd:sequence maxOccurs="1">
<xsd:element name="MiddleElement">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="ChildElement" type="ns1:IDHolder"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="ObjectId" type="xsd:IDREF" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:t="urn:test"
exclude-result-prefixes="xs math" version="3.0" expand-text="yes">
<xsl:mode streamable="yes" use-accumulators="#all"/>
<xsl:import-schema schema-location="issuereporo.xsd" namespace="urn:test"/>
<xsl:accumulator name="acc" as="node()?" initial-value="()" streamable="yes">
<xsl:accumulator-rule xmlns:saxon="http://saxon.sf.net/" match="t:MiddleElement" select="."
phase="end" saxon:capture="yes"/>
</xsl:accumulator>
<xsl:template match="t:RootElement">
<xsl:apply-templates />
<xsl:variable name="vAcc" select="accumulator-after('acc')"/>
Direct Access
{$vAcc/id('_1')}
Access via context node
<!--THIS IS WHAT DOESN'T WORK-->
{$vAcc/id(@ObjectId)}
Access via global
<!-- will only work when streaming is off -->
{id(@ObjectId)}
</xsl:template>
</xsl:stylesheet>
XML
<?xml version="1.0" encoding="UTF-8"?>
<RootElement xmlns="urn:test" ObjectId="_2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:test file:/C:/Users/john/Documents/GitHub/streamatron-test/issuereporo.xsd">
<MiddleElement>
<ChildElement ObjectId="_1">C
</ChildElement>
<ChildElement ObjectId="_2">D
</ChildElement>
</MiddleElement>
</RootElement>
我想你想要 {$vAcc/id(current()/@ObjectId)}
而不是 {$vAcc/id(@ObjectId)}
。