説明:Multipile「ではない」condtions(XSLT)
私は属性と入ってくるフィールドの値をチェックする必要がある要件を持っている、との両方がNULLでない場合、私は中にこれらの値を移入出力。
問題:値の一つでも渡されたとき、私は出力を取得しています
(属性や実際のフィールド値のいずれか)。入力XMLの「両方」のために 'と'の条件が必要なので、そうではありません。
私は2つの入力XMLを持っている:
最初:
<a>
<b Ccy="INR">999.000</b>
</a>
秒:
<v>
<z Ccy="USD">9999.000</z>
</v>
コードを使用:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:output encoding="UTF-8"
version="1.0"
method="xml"
indent="yes"/>
<xsl:template match="/">
<xsl:variable name="ccy1"
select="./*[local-name()='a']
/*[local-name()='b']
/@*[local-name()='Ccy']"/>
<xsl:variable name="field1"
select="./*[local-name()='a']
/*[local-name()='b']"/>
<xsl:variable name="ccy2"
select="./*[local-name()='v']
/*[local-name()='z']
/@*[local-name()='Ccy']"/>
<xsl:variable name="field2"
select="./*[local-name()='v']
/*[local-name()='z']"/>
<xsl:if test="not($ccy1 = '')
and not($field1 = '')
or not($ccy2 = '')
and not($field2 = '')">
<output Ccy="AAA">
<xsl:choose>
<xsl:when test="$ccy1 and $field1">
<xsl:attribute name="Ccy">
<xsl:value-of select="$ccy1"/>
</xsl:attribute>
<xsl:value-of select="$field1"/>
</xsl:when>
<xsl:when test="$ccy2 and $field2">
<xsl:attribute name="Ccy">
<xsl:value-of select="$ccy2"/>
</xsl:attribute>
<xsl:value-of select="$field2"/>
</xsl:when>
</xsl:choose>
</output>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
なぜあなたは '* [ローカル名()= '']'のような恐ろしいハックを使うのでしょうか? –
これはXPathを取得する通常の方法ですか? –
いいえ、そうではありません。要素が名前空間にある場合は、 'a'または--ns1:a'(名前空間を宣言し、' ns1'接頭辞にバインドした後)を使用します。 –