如何在XSLT中只显示两项? [英] how to show only two items in xslt?
本文介绍了如何在XSLT中只显示两项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我如何显示前两个元素是XSLT? 以下是我的代码 http://xsltransform.net/ehVYZMp/6
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="a">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates select="t"/>
</hmtl>
</xsl:template>
<xsl:template match="t[@live='2']">
<xsl:value-of select="@b"/>
</xsl:template>
</xsl:transform>
预期产量:12
推荐答案
如果您只想选择live
属性设置为"2"的前两个t
元素,则可以将此逻辑放入xsl:apply-templates
而不是模板匹配
<xsl:apply-templates select="t[@live='2'][position() < = 2]"/>
尝试此XSLT
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="a">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates select="t[@live='2'][position() < = 2]"/>
</hmtl>
</xsl:template>
<xsl:template match="t">
<xsl:value-of select="@b"/>
</xsl:template>
</xsl:transform>
这篇关于如何在XSLT中只显示两项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文