开发者

how to find out if an attribute exists or not in XSL

开发者 https://www.devze.com 2023-02-08 18:40 出处:网络
how to find out if an attr开发者_Go百科ibute exists or not in XSL.Just use: <xsl:template match=\"someElement/@someAttrName\">

how to find out if an attr开发者_Go百科ibute exists or not in XSL.


Just use:

<xsl:template match="someElement/@someAttrName">
  <!-- Whatever specific work when someElement has @someAttrName -->
</xsl:template>

<xsl:template match="someElement[not(@someAttrName)]">
  <!-- Whatever specific work when someElement has no @someAttrName -->
</xsl:template>

Do note: In a well-written XSLT code the number of conditional instructions (such as <xsl:choose>, <xsl:when>, <xsl:otherwise>, <xsl:if>, ... etc.) is close to zero. In this solution it is 0.


<xsl:choose>
   <xsl:when test="element/@attribute">
     do one thing
   </xsl:when>
   <xsl:otherwise>
     do something else
   </xsl:otherwise>
</xsl:choose>


<xsl:value-of select="element[not(@attribute)]"/>

if need select some element without attribute

0

精彩评论

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

关注公众号