1

I'm merging two files, a WADL file and an XML file containing DITA fragments to ultimately generate a DITA file. the DITA fragments can be a string of text or a block of DITA tags. trying to determine if an element in the DITA fragments file is populated (or even exists) with the following test:

<xsl:variable name="docIDtext" select="$docId//doc[@id=$resourcepath]/*|text()"/>
<xsl:choose>
    <xsl:when test="$docIDtext">
        <xsl:copy-of select="$docIDtext"/>
    </xsl:when>
    <xsl:otherwise>
        <draft-comment author="doc">FIXME: missing DocID</draft-comment>
    </xsl:otherwise>
</xsl:choose>

however, the test for $docIDtext is always true, which is not the correct result. it's that pesky "*". How can I do this test?

4

1 回答 1

1

如果没有输入文档和预期的输出,这有点难以分辨,但我想解决方法是这样写:

<xsl:variable name="docIDtext" select="
    $docId//doc[@id=$resourcepath]/* |
    $docId//doc[@id=$resourcepath]/text()
"/>

表单的表达式a/b|c被评估为(a/b) | c, not a/(b|c),后者在 XPath 1.0 中无论如何都是无效的。

上面的xsl:variable指令可以通过使用doc元素的临时值来优化。但最好的解决方案可能是使用node()将匹配任何类型的子节点的节点测试:

<xsl:variable name="docIDtext" select="$docId//doc[@id=$resourcepath]/node()"/>

这将返回子元素和文本节点(还有注释和处理指令)。

于 2014-11-07T16:45:27.393 回答