如何过滤模板内数组中的项目?

How can I filter items in an array inside a template?

您好,我在 XSL 和过滤数组方面遇到了问题。

这是我的 XSL 转换:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns0="http://xmlns.sse.com/SSEPD/GIS/PublishChangeSetEBM" xmlns:tns="http://xmlns.sse.com/SSEPD/GIS/UpdateLocationEBM" xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:ns1="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns3="http://iec.ch/2002/schema/CIM_difference_model#" xmlns:ns4="http://xmlns.sse.com/SSEPD/GIS/ChangeSetEBO" xmlns:ns5="http://iec.ch/TC57/2010/CIM-schema-cim15#" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns2="http://xmlns.sse.com/Enterprise/Common" xmlns:client="http://xmlns.oracle.com/GIS_R1_SOA/SubstationEBS/SubstationEBS" xmlns:ns7="http://www.ibm.com/maximo" xmlns:ns6="http://xmlns.oracle.com/GIS_R1_SOA/UpdateLocationProviderABCS/UpdateLocationProviderABCS" xmlns:ns8="http://xmlns.sse.com/SSEPD/GIS/UpdateLocationEBO">
<xsl:variable name="ID_HASH">#</xsl:variable>
<xsl:template match="/">
    <tns:UpdateLocationEBM>
        <tns:DataArea>
            <ns7:SyncSSENLOCATIONS>
                <ns7:SSENLOCATIONSSet>
                    <xsl:apply-templates select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Substation"/>
                </ns7:SSENLOCATIONSSet>
            </ns7:SyncSSENLOCATIONS>
        </tns:DataArea>
    </tns:UpdateLocationEBM>
</xsl:template>
<xsl:template match="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Substation">
    <ns7:LOCATIONS>
        <xsl:variable name="CURRENT_SUB" select="."/>
        <ns7:CURRENT_SUB>
            <xsl:value-of select="$CURRENT_SUB"/>
        </ns7:CURRENT_SUB>
        <xsl:variable name="LOCATION" select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Location[@ns1:ID = substring-after($CURRENT_SUB/ns5:PowerSystemResource.Location/@ns1:resource, $ID_HASH)]"/>
        <xsl:variable name="VOLTAGE_LEVEL" select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:VoltageLevel[ns5:VoltageLevel.Substation/@ns1:resource = concat($ID_HASH,$CURRENT_SUB/@ns1:ID)]"/>
        <ns7:VOLTAGE_LEVEL>
            <xsl:value-of select="$VOLTAGE_LEVEL"/>
        </ns7:VOLTAGE_LEVEL>
        <ns7:LOCATION>
            <xsl:value-of select="$LOCATION/ns5:Location.ngr"/>
        </ns7:LOCATION>
    </ns7:LOCATIONS>
</xsl:template>
</xsl:stylesheet>

这是 XML 输入:

<PublishChangeSetRequestEBM xmlns:cim="http://iec.ch/TC57/2010/CIM-schema-cim15#" xmlns:ns5="http://iec.ch/TC57/2010/CIM-schema-cim15#" xmlns:dm="http://iec.ch/2002/schema/CIM_difference_model#" xmlns:ns3="http://iec.ch/2002/schema/CIM_difference_model#" xmlns:ebo="http://xmlns.sse.com/SSEPD/GIS/ChangeSetEBO" xmlns:tns="http://xmlns.sse.com/SSEPD/GIS/PublishChangeSetEBM" xmlns="http://xmlns.sse.com/SSEPD/GIS/PublishChangeSetEBM" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns1="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns4="http://xmlns.sse.com/SSEPD/GIS/ChangeSetEBO" xmlns:ns0="http://xmlns.sse.com/SSEPD/GIS/PublishChangeSetEBM">
<tns:DataArea>
    <ebo:ChangeSet>
        <ebo:JobID>100035</ebo:JobID>
        <ebo:FileName>Substation_XREF.rdf</ebo:FileName>
        <rdf:RDF>
            <dm:DifferenceModel rdf:about="">
                <dm:forwardDifferences rdf:parseType="Statements">
                    <cim:Substation rdf:ID="IL_SUB001">
                        <cim:PowerSystemResource.Location rdf:resource="#SUB_loc001"/>
                    </cim:Substation>
                    <cim:VoltageLevel rdf:ID="VOL_001">
                        <cim:VoltageLevel.Substation rdf:resource="#IL_SUB001"/>
                    </cim:VoltageLevel>
                    <cim:Location rdf:ID="SUB_loc001">
                        <cim:Location.ngr>SU33736744</cim:Location.ngr>
                    </cim:Location>
                </dm:forwardDifferences>
            </dm:DifferenceModel>
        </rdf:RDF>
    </ebo:ChangeSet>
</tns:DataArea>
</PublishChangeSetRequestEBM>

我遇到的问题是变量 $VOLTAGE_LEVEL。由于某种原因,我在模板函数中定义变量时应用的过滤条件不起作用。使用它的标签 ns7:VOLTAGE_LEVEL 在输出中为空。

我已经用不同的工具仔细检查过,并且做了不同的测试,看起来问题出在 $CURRENT_SUB 变量上。但这很奇怪,因为标签 ns7:LOCATION 正在显示正确的信息,并且它使用的变量 $LOCATION 是通过使用与 $VOLTAGE_LEVEL.

相同的方法填充的

你能看看吗?我一头雾水

注意:我使用的是样式表 2.0 版

亲切的问候 尼克

您可以试试这个修改后的模板和谓词值:

<xsl:template match="/">
    <tns:UpdateLocationEBM>
        <tns:DataArea>
            <ns7:SyncSSENLOCATIONS>
                <ns7:SSENLOCATIONSSet>
                    <xsl:apply-templates
                        select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Substation" />
                </ns7:SSENLOCATIONSSet>
            </ns7:SyncSSENLOCATIONS>
        </tns:DataArea>
    </tns:UpdateLocationEBM>
</xsl:template>
<xsl:template
    match="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Substation">
    <ns7:LOCATIONS>
        <xsl:variable name="CURRENT_SUB" select="."/>

        <ns7:CURRENT_SUB>
            <xsl:value-of select="$CURRENT_SUB" />
        </ns7:CURRENT_SUB>

        <xsl:variable name="LOCATION"
            select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:Location[@ns1:ID = substring-after($CURRENT_SUB/ns5:PowerSystemResource.Location/@ns1:resource, $ID_HASH)]" />
        <xsl:variable name="VOLTAGE_LEVEL"
            select="/ns0:PublishChangeSetRequestEBM/ns0:DataArea/ns4:ChangeSet/ns1:RDF/ns3:DifferenceModel/ns3:forwardDifferences/ns5:VoltageLevel/ns5:VoltageLevel.Substation[@ns1:resource = concat($ID_HASH,$CURRENT_SUB/@ns1:ID)]" />

        <ns7:VOLTAGE_LEVEL>
            <xsl:value-of select="$VOLTAGE_LEVEL" />
        </ns7:VOLTAGE_LEVEL>
        <ns7:LOCATION>
            <xsl:value-of select="$LOCATION/ns5:Location.ngr" />
        </ns7:LOCATION>
    </ns7:LOCATIONS>
</xsl:template>