我知道这是一个非常简单的问题,但不知怎的,我的XSLT无效。我在XML之下,我需要从中获取最后一个索引号。在这种情况下它是10.有人可以提供xsl。谢谢你的帮助:
<?xml version="1.0" encoding="UTF-8"?>
<messages xmlns="http://www.workday.com/wd-queue/17" returned-count="11" total-count="11">
<message>
<index>4</index>
<uri>/ccx/wd-queue/queue_service_pxd/messages/4</uri>
<size>1869</size>
<uploaded>2016-06-14T14:14:47.000Z</uploaded>
<content-type>text/xml;charset=UTF-8</content-type>
</message>
<message>
<index>5</index>
<uri>/ccx/wd-queue/queue_service_pxd/messages/5</uri>
<size>1820</size>
<uploaded>2016-06-14T17:23:28.000Z</uploaded>
<content-type>text/xml;charset=UTF-8</content-type>
</message>
<message>
<index>6</index>
<uri>/ccx/wd-queue/queue_service_pxd/messages/6</uri>
<size>1435</size>
<uploaded>2016-06-14T17:45:45.000Z</uploaded>
<content-type>text/xml;charset=UTF-8</content-type>
</message>
<message>
<index>7</index>
<uri>/ccx/wd-queue/queue_service_pxd/messages/7</uri>
<size>159031</size>
<uploaded>2016-06-14T17:49:27.000Z</uploaded>
<content-type>text/xml;charset=UTF-8</content-type>
</message>
<message>
<index>10</index>
<uri>/ccx/wd-queue/queue_service_pxd/messages/10</uri>
<size>1044</size>
<uploaded>2016-06-14T18:07:31.000Z</uploaded>
<content-type>text/xml;charset=UTF-8</content-type>
</message>
</messages>
XSLT我正在使用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.workday.com/wd-queue/17">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/*/message[last()]/index"/>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:2)
以这种方式尝试:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://www.workday.com/wd-queue/17">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/ns1:messages">
<xsl:apply-templates select="ns1:message[last()]/ns1:index"/>
</xsl:template>
</xsl:stylesheet>