开发者

XSLT: Check if tag exists on the outputted XML

How can I check if a tag exists using xslt? The difference being that i want to check the XML that I am creating (not the input XML).

Kinda like开发者_JS百科 <xsl:when test="phone"> but for the output instead.


The result tree of a stylesheet is write-only. If you want to read it, you can do that from another transformation - pipelines of transformations are a useful design pattern. But you haven't said what problem you are trying to solve.


Unless you chain two stylesheets where the second takes the result from the first as its input or unless you store a result in a variable with e.g.

<xsl:variable name="temp-result">
 <xsl:apply-templates/>
<xsl:variable>

<xsl:if test="$temp-result//phone">
  <xsl:copy-of select="$temp-result"/>
</xsl:if>

I don't think there is a way. Note that above approach with a variable works that way with XSLT 2.0, with 1.0 you would need to use an extension function like exsl:node-set in test="exsl:node-set($temp-result)//phone".

A third option might exist with schema-aware XSLT 2.0 by validating a result against a schema, that way you could ensure the result is an instance of a schema.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜