0

すべての INST 名をリストする必要がありますが、上記の XML 本体の「inst/idef」部分に「onlyTesters」ノードが存在しない場合のみです。

奇妙なことだとは思いますが、受け取った XML を変更することはできません。

XML:

<river>
    <station num="699">
        <inst name="FLU(m)" num="1">
            <idef></idef>
        </inst>
        <inst name="Battery(V)" num="18">
            <idef>
                <onlyTesters/>
            </idef>
        </inst>
    </station>
    <INST name="PLU(mm)" num="0" hasData="1" virtual="0"/>
    <INST name="FLU(m)" num="1" hasData="1" virtual="0"/>
    <INST name="Q(m3/s)" num="3" hasData="1" virtual="1"/>
    <INST name="Battery(V)" num="18" hasData="1" virtual="0"/>
</river>

XSL:

<xsl:template match="/">
    <xsl:apply-templates select="//INST[@hasData = 1 and not(//inst[@num=(current()/@num)]/idef/onlyTesters)]/@name"/>
 </xsl:template>

<xsl:template match="//INST[@hasData = 1 and not(//inst[@num=(current()/@num)]/idef/onlyTesters)]/@name">
    <xsl:value-of select="@name"/>,
</xsl:template>

私は一致していません。

これは私が期待する結果です:

PLU(mm),FLU(m),Q(m3/s)
4

2 に答える 2

0

相互参照は、キーを使用して解決するのが最適です。たとえば、次のようになります。

XSLT1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" />

<xsl:key name="inst" match="inst" use="@name" />

<xsl:template match="/river">
    <xsl:for-each select="INST[@hasData = 1 and not(key('inst', @name)/idef/onlyTesters)]">
        <xsl:value-of select="@name"/>
        <xsl:if test="position() != last()">,</xsl:if>
    </xsl:for-each>
</xsl:template> 

</xsl:stylesheet>

またはさらに簡単です:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" />

<xsl:key name="exclude" match="onlyTesters" use="ancestor::inst/@name" />

<xsl:template match="/river">
    <xsl:for-each select="INST[@hasData = 1 and not(key('exclude', @name))]">
        <xsl:value-of select="@name"/>
        <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
</xsl:template> 

</xsl:stylesheet>
于 2019-08-20T22:09:00.110 に答える