在XSLT中,当涉及到'if'时,保持代码DRY的首选方法是什么?
目前我这样做:
<xsl:if test="select/some/long/path">
<element>
<xsl:value-of select="select/some/long/path" />
</element>
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
我宁愿只写一次"select/some/long/path".
我明白你的意思了.当路径长200个字符时代码会变得混乱.
您可以将其添加到变量中
<xsl:variable name="path" select="select/some/long/path"/>
<xsl:if test="$path">
<xsl:value-of select="$path" />
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
701 次 |
最近记录: |