将节点连接到包含正斜杠和美元符号的字符串

时间:2016-08-29 17:10:47

标签: xslt xslt-1.0

这是我期望的XML结果:

        <category>
            <text>
                $course$/something
            </text>
        </category>

这就是我的尝试:

        <xsl:variable name="course">$course$/</xsl:variable>
        <category>
            <text>
                <xsl:value-of select="concat('$course', /office:document/office:meta/dc:title)" />
                <xsl:value-of select="concat('\$course\$/', /office:document/office:meta/dc:title)" />
                <xsl:value-of select="concat('&#36;course&#36;/', /office:document/office:meta/dc:title)" />                   
            </text>
        </category>

使用<xsl:value-of select="concat('hello ', 'world')"/>会得到预期的结果,但上述value-of都不起作用。所有这些都给出一个空字符串(<text />)。

我假设节点/office:document/office:meta/dc:title将被强制转换为字符串,但我仍然对于逃避美元符号和正斜杠的正确方法感到困惑。

1 个答案:

答案 0 :(得分:1)

为什么你不能简单地做到:

<xsl:variable name="course">$course$/</xsl:variable>
<category>
    <text>
        <xsl:value-of select="concat($course, /office:document/office:meta/dc:title)" />                
    </text>
</category>
</xsl:template>

或者,如果你必须:

    <android.support.v7.widget.AppCompatImageButton
        android:id="@+id/imageButtonI"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/icolor"
        android:tint="@color/accent"
        app:srcCompat="@drawable/magnify"/>

    <ImageButton
        android:id="@+id/imageButtonS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/scolor"
        android:tint="@color/accent"
        android:src="@drawable/magnify"/>

请注意变量周围缺少引号。