0

パラメータで XSL が機能しない

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="reportname" />
<xsl:param name="quarter" />
<xsl:param name="menteename" />

<xsl:template match="AllReports" >
<xsl:for-each select="./Report[@Name=$reportname]" >
    <table border="0" class="dottedlines" cellpadding="2" cellspacing="0">

    <xsl:for-each select="Record[@Period=$quarter] and ($menteename)] >

<tr>
    <xsl:for-each select="Entry">
 <td><xsl:value-of select="." disable-output-escaping="yes"/></td>
               </xsl:for-each>
</tr>

    </xsl:for-each>
</table>

    </xsl:for-each>

    </xsl:template>
</xsl:stylesheet>

ハードコードされた値を扱う私のXSL

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="reportname" />
<xsl:param name="quarter" />
<xsl:param name="menteename" />

<xsl:template match="AllReports" >
<xsl:for-each select="./Report[@Name=$reportname]" >
    <table border="0" class="dottedlines" cellpadding="2" cellspacing="0">

    <xsl:for-each select="Record[@Period=$quarter] and (Entry= 'Dhirde, Govinda' or Entry= 'Vaze, Kedar')] >

<tr>
    <xsl:for-each select="Entry">
 <td><xsl:value-of select="." disable-output-escaping="yes"/></td>
               </xsl:for-each>
</tr>

    </xsl:for-each>
</table>

    </xsl:for-each>

    </xsl:template>
</xsl:stylesheet>

変数 $menteename = "Entry= 'Dhirde, Govinda' or Entry= 'Vaze, Kedar'" の値を渡しています。しかし、ハードコードされたものは、パラメーターのものではなくうまく機能します。パラメータ値内のタグを読み取る XSL 解析に問題があることがわかりました。これが問題の原因ですか。どうすればこれを機能させることができますか?

4

2 に答える 2

0

変数は、式ではなく値を保持します。(@x = 3) のような式を、値が文字列 "@x = 3" である変数に置き換えることはできません。そのようなことを行うには、saxon:evaluate() や XSLT 3.0 の xsl:evaluate など、文字列として提供される XPath 式を評価する拡張機能が必要です。

于 2013-02-22T13:34:10.477 に答える
0

xslt-2.0特に、プレーンな文字列値だけでなく一連の文字列を渡す可能性がある場所として質問がタグ付けされているため、どのタイプのパラメーター値とどの値をスタイルシートに渡すかを本当に知る必要があります。

一連の文字列を渡すと仮定すると、'Dhirde, Govinda', 'Vaze, Kedar'簡単にテストできます

  Entry = $menteename

あなたの述語で。

複数の名前を含むプレーンな文字列を渡す場合、もちろん文字列は個々の値に分割する必要があります。値にはすでにコンマが含まれているため、別のセパレータが必要です。たとえば、文字列値が be で渡された'Dhirde, Govinda|Vaze, Kedar'場合、

Entry = tokenize($menteename, '\|')

あなたの述語で。

XSLT 1.0 を使用していて、パラメーターの文字列値を分割する拡張関数を使用できない、または使用したくないと仮定すると、次のようなチェックを使用できます。

contains(concat('|', $menteename, '|'), concat('|', Entry, '|'))

Entryこれは、要素に次のような単一の値が含まれていることを前提としており、名前の個別のリストを パラメーター値などとしてVaze, Kedar渡すと、そのチェックは行われますbar'Dhirde, Govinda|Vaze, Kedar'

contains('|Dhirde, Govinda|Vaze, Kedar|', '|Vaze, Kedar|')
于 2013-02-22T10:58:46.127 に答える