Xml Xslt条件排序两次,有N个值
XSLT文件Xml Xslt条件排序两次,有N个值,xml,sorting,xslt,Xml,Sorting,Xslt,XSLT文件 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:template match="/"> <xsl:call-template name="content"> </xsl:call
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="/">
<xsl:call-template name="content">
</xsl:call-template>
</xsl:template>
<xsl:template name="content">
<movies>
<xsl:for-each select="/movies/movie">
<xsl:for-each select="movie[starts-with(name,'Ka')]">
<xsl:apply-templates select="name" />
<xsl:apply-templates select="vdate" />
</xsl:for-each>
<xsl:for-each select="/movies/movie">
<xsl:sort select="date" data-type="number" order="descending"/>
<xsl:if test="position() <= 50">
<xsl:value-of select="vdate"/>
</xsl:if>
</xsl:for-each>
<xsl:sort select="date" data-type="number" order="'.($this->_boolAscending?'ascending':'descending').'"/>
<movie>
<vdate><xsl:value-of select="vdate"/></vdate>
<no><xsl:value-of select="no"/></no>
<name><xsl:value-of select="name"/></name>
<link1><xsl:value-of select="link1"/></link1>
<link2><xsl:value-of select="link2"/></link2>
<link3><xsl:value-of select="link3"/></link3>
<year><xsl:value-of select="year"/></year>
</movie>
</xsl:for-each>
</movies>
</xsl:template>
</xsl:stylesheet>
名称以“K”字母开头,然后按日期排序[?]并按降序排列
秩序。仅显示前50个值
如果我理解正确,那么这就足够了:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"
cdata-section-elements="link1 link2 link3"/>
<xsl:template match="/movies">
<xsl:copy>
<xsl:apply-templates select="movie[starts-with(name, 'K')]">
<xsl:sort select="date" data-type="number" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="movie">
<xsl:if test="position() <= 50">
<xsl:copy>
<xsl:copy-of select="vdate"/>
<xsl:copy-of select="no"/>
<xsl:copy-of select="name"/>
<xsl:copy-of select="link1"/>
<xsl:copy-of select="link2"/>
<xsl:copy-of select="link3"/>
<xsl:copy-of select="year"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
添加:
对于HTML输出,请尝试以下操作:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/movies">
<html>
<body>
<h1>Movie Information</h1>
<xsl:apply-templates select="movie[starts-with(name, 'K')]">
<xsl:sort select="date" data-type="number" order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="movie">
<xsl:if test="position() <= 50">
<h4>
<xsl:value-of select="name"/><br/>
<xsl:value-of select="year"/>
</h4>
<p>
Download - <xsl:value-of select="link1" disable-output-escaping="yes"/><br/>
Download - <xsl:value-of select="link2" disable-output-escaping="yes"/><br/>
Download - <xsl:value-of select="link3" disable-output-escaping="yes"/>
</p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
电影信息
下载-
下载-
下载-
您是否可以编辑您的问题以显示您期望的输出?谢谢您解决了我的问题。它在xml数据输出中非常有效。在html输出中使用时未获得超链接值。@user2162901我添加了一个带有html输出的变体。感谢您出色的工作和时间。它工作得很好。再次感谢你。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"
cdata-section-elements="link1 link2 link3"/>
<xsl:template match="/movies">
<xsl:copy>
<xsl:apply-templates select="movie[starts-with(name, 'K')]">
<xsl:sort select="date" data-type="number" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="movie">
<xsl:if test="position() <= 50">
<xsl:copy>
<xsl:copy-of select="vdate"/>
<xsl:copy-of select="no"/>
<xsl:copy-of select="name"/>
<xsl:copy-of select="link1"/>
<xsl:copy-of select="link2"/>
<xsl:copy-of select="link3"/>
<xsl:copy-of select="year"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/movies">
<html>
<body>
<h1>Movie Information</h1>
<xsl:apply-templates select="movie[starts-with(name, 'K')]">
<xsl:sort select="date" data-type="number" order="descending"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="movie">
<xsl:if test="position() <= 50">
<h4>
<xsl:value-of select="name"/><br/>
<xsl:value-of select="year"/>
</h4>
<p>
Download - <xsl:value-of select="link1" disable-output-escaping="yes"/><br/>
Download - <xsl:value-of select="link2" disable-output-escaping="yes"/><br/>
Download - <xsl:value-of select="link3" disable-output-escaping="yes"/>
</p>
</xsl:if>
</xsl:template>
</xsl:stylesheet>