Xml 我想把捐款按先后顺序排列。
我希望vDonations的顺序是分散的,当我尝试运行它时,会出现此错误Xml 我想把捐款按先后顺序排列。,xml,xslt,Xml,Xslt,我希望vDonations的顺序是分散的,当我尝试运行它时,会出现此错误 Unexpected element xsl:sort 代码 灯塔捐赠名单 捐赠者 捐赠 如果您希望同一个人的捐赠按降序显示在一个td中,请使用以下命令: <xsl:template match="person"> <tr> <td colspan="1"> <xsl:value-of select="concat(firstN
Unexpected element
xsl:sort
代码
灯塔捐赠名单
捐赠者
捐赠
如果您希望同一个人的捐赠按降序显示在一个td
中,请使用以下命令:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
,
如果您想按降序显示所有捐赠,请将您的转换修改为此项:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
灯塔捐赠名单
捐赠者
捐赠
使用您在第一个问题中提供的两个XML文件执行此转换时,将生成所需的正确结果:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
灯塔捐赠名单
捐赠者
捐赠
戴维奥尔森5133橡树街德尔福肯塔基州89011(532)555-8981
10000
简·惠特尼山头大道87号肯塔基州贾斯珀89381(534)555-7493
10000
李托马斯451安文苑贾斯珀肯塔基州89381(534)555-9082
100
肯塔基州德尔福市爱丽丝大道31号辛迪吴89011(532)555-7212
50
如果您希望同一个人的捐赠按降序显示在一个td
中,请使用以下命令:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
,
如果您想按降序显示所有捐赠,请将您的转换修改为此项:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
灯塔捐赠名单
捐赠者
捐赠
使用您在第一个问题中提供的两个XML文件执行此转换时,将生成所需的正确结果:
<xsl:template match="person">
<tr>
<td colspan="1">
<xsl:value-of select="concat(firstName, ' ', lastName)"/>
<xsl:value-of select="concat(' ',street,' ' , city,' ', state, ' ', zip, ' ', phone)"/>
</td>
<td colspan="1">
<xsl:for-each select="$vDonations/*/*[@pin = current()/@pid]">
<xsl:sort select="@amount"
data-type="number" order="descending"
case-order="upper-first"/>
<xsl:if test="position() >1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="@amount"/>
</xsl:for-each>
</td>
</tr>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="ppathDonations" select=
"'file:///c:/temp/delete/donations.xml'"/>
<xsl:param name="ppathPersons" select=
"'file:///c:/temp/delete/persons.xml'"/>
<xsl:variable name="vPersons" select=
"document($ppathPersons)"/>
<xsl:variable name="vDonations" select=
"document($ppathDonations)"/>
<xsl:template match="/">
<html>
<head>
<link href="money.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p>
<img src="logo.jpg"/>
</p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<xsl:apply-templates select=
"$vDonations/*/donation">
<xsl:sort select="@amount" data-type="number"
order="descending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="donation">
<xsl:variable name="vPerson" select=
"$vPersons/*/person[@pid = current()/@pin]"/>
<tr>
<td colspan="1">
<xsl:value-of select=
"concat($vPerson/firstName, ' ', $vPerson/lastName)"/>
<xsl:value-of select=
"concat(' ', $vPerson/street,' ' ,
$vPerson/city,' ',
$vPerson/state, ' ',
$vPerson/zip, ' ',
$vPerson/phone)"/>
</td>
<td colspan="1">
<xsl:value-of select="@amount"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="money.css" rel="stylesheet" type="text/css">
</head>
<body>
<h2>The Lighthouse Donation List</h2>
<p><img src="logo.jpg"></p>
<table>
<tr>
<th>Donor</th>
<th>Donation</th>
</tr>
<tr>
<td colspan="1">David Olson 5133 Oak Street Delphi KY 89011 (532) 555-8981</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Jane Whitney 87 Hilltop Drive Jasper KY 89381 (534) 555-7493</td>
<td colspan="1">10000</td>
</tr>
<tr>
<td colspan="1">Lee Thomas 451 Unwin Court Jasper KY 89381 (534) 555-9082</td>
<td colspan="1">100</td>
</tr>
<tr>
<td colspan="1">Cindy Wu 31 Alice Avenue Delphi KY 89011 (532) 555-7212</td>
<td colspan="1">50</td>
</tr>
</table>
</body>
</html>
灯塔捐赠名单
捐赠者
捐赠
戴维奥尔森5133橡树街德尔福肯塔基州89011(532)555-8981
10000
简·惠特尼山头大道87号肯塔基州贾斯珀89381(534)555-7493
10000
李托马斯451安文苑贾斯珀肯塔基州89381(534)555-9082
100
肯塔基州德尔福市爱丽丝大道31号辛迪吴89011(532)555-7212
50
我尝试了几种不同的方法,但都失败了。现在还不清楚你到底想要什么。无论如何,在我的回答中,我给出了两种可能的需要处理的情况的解决方案;对单身汉进行分类是没有意义的。xsl:sort需要进入选择一系列节点的xsl:for-each或xsl:apply模板中。但是“Unexpected element xsl:sort”的消息似乎很奇怪。我怀疑这不是来自上面的代码,而是来自其他一些不正确的尝试。它确实来自上面的代码。我尝试了几种不同的方法,但都失败了。不清楚您到底想要什么。无论如何,在我的回答中,我给出了两种可能的需要处理的情况的解决方案;对单身汉进行分类是没有意义的。xsl:sort需要进入选择一系列节点的xsl:for-each或xsl:apply模板中。但是“Unexpected element xsl:sort”的消息似乎很奇怪。我怀疑这不是来自上面的代码,而是来自其他错误的尝试。它确实来自上面的代码。