如何查找XSL中是否存在属性

时间:2022-07-25 20:32:39

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

如何查明在XSL中是否存在某个属性。

3 个解决方案

#1


26  

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.

注意:在编写良好的XSLT代码中,条件指令的数量(如 ,…)等)接近于零。这个解是0。 否则> 选择>

#2


19  

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

#3


1  

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

if need select some element without attribute

如果需要选择一些没有属性的元素

#1


26  

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.

注意:在编写良好的XSLT代码中,条件指令的数量(如 ,…)等)接近于零。这个解是0。 否则> 选择>

#2


19  

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

#3


1  

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

if need select some element without attribute

如果需要选择一些没有属性的元素