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

时间:2018-11-29 12:07:30

标签: xml xslt xls

您好,我在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版样式表

亲切的问候 尼克

1 个答案:

答案 0 :(得分: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>