xml - 替换 xsl/xslt 中的值
问题描述
我正在研究一个 xsl 样式表。我以表格格式显示标题、艺术家和他们的国家。现在我需要用他们的首都替换国家。如何创建映射(键,值)并将其替换为列。下面是我的示例 xml。
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
</cd>
</catalog>
这是我正在使用的样式表
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我需要一个映射,这样每当国家名称为英国时,它将被替换为与其他国家相同的首都伦敦。是否有某种方法可以将 UK 定义为键,将 London 定义为值,这样每当我收到作为 UK 的键时,它将被其值替换。请帮忙。
解决方案
推荐阅读
- express - 如何使用相同的路线,一条带参数,一条不带?
- html - 如何在没有背景“故障”的情况下添加 HTML 按钮?
- c# - 实体框架错误:已经有一个打开的 DataReader 与此命令关联
- tkinter - 我正在用 Python 创建一个 gui 程序,但作业没有运行
- azure - 用于对用户进行身份验证的 Azure 应用程序
- java - 在 java 中使用 aws lambda 将记录分批放入 kinesis firehose
- css - @keyframes 动画在 Safari(macOS、iOS)上不起作用
- flutter - Flutter 中的 Clean Architecture 在哪里执行状态更改?
- javascript - 使用 JS 或 jQuery 将类添加到文本行
- excel - 如何忽略数据透视表中特定字段的特定过滤器?