xml - XSLT 比较属性和值
问题描述
嘿,我有一个关于作业的快速问题
我的 xml 中有一个列表,其中包含这样的电影商店的类型:
......
<genre ID="G3" name="Action"/>
<genre ID="G4" name="Romance"/>
<genre ID="G5" name="Sci-fi">
....和更多
和一个电影列表,它指的是这样的流派:
<movie ID = "F6" titel ="Blood Work" year = "2002" length = "109">
<!-- Genres -->
<genre ID ="G11" />
<genre ID ="G7" />
......
在图片中你可以看到我到目前为止得到了什么。而不是流派 ID(G5 和 G3)等等,我想要它的名称。这就是我到目前为止感到疲倦的原因:
<?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>
<xsl:apply-templates select="*"/>
</body>
</html>
</xsl:template>
<xsl:template match="movieshop">
<table border="1">
<tr bgcolor="#9acd32">
<!--Strukturierung der Tabelle -->
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th>Genre</th>
<th>Length (in Minuten)</th>
<th>Year</th>
</tr>
<!--fill table with the elements movies -->
<xsl:for-each select="//movieshop/movies/movie">
<tr>
<!-- ID of the movie -->
<td><xsl:value-of select="@ID"/></td>
<!-- titel of the movie -->
<td><xsl:value-of select="@titel"/></td>
<!-- Description of the movie -->
<td><xsl:value-of select="details/@inhalt"/></td>
<!-- Genre of the movie -->
<td>
<xsl:for-each select="genre/@ID">
<xsl:call-template name="resultGenres">
<xsl:with-param name="id" select="."/>
</xsl:call-template>
</xsl:for-each>
</td>
<!-- Length -->
<td><xsl:value-of select="@length"/></td>
<!-- Year -->
<td><xsl:value-of select="@year"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="resultGenres">
<xsl:param name="id"/>
<!--Just testing what id is -->
<p>Genre: <xsl:value-of select = "$id" /></p>
<xsl:for-each select="//movieshop/genres/genre[ID=$id]">
<xsl:call-template name="resultGenre"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="resultGenre">
<xsl:value-of select="//movieshop/genres/genre/@name"/>
<br/>
</xsl:template>
</xsl:stylesheet>
错误必须在这里的某个地方:
<xsl:for-each select="//movieshop/genres/genre[ID=$id]">
即使 G1 等存在于我的列表中,也没有结果集。如果我在代码中拼错了一些东西,我很抱歉。尝试将所有单词更改为英语。先谢谢了
解决方案
推荐阅读
- javascript - 如何在 Nodejs 模块 Regex 中使用土耳其语字符
- c# - 如何在 C# 中为 WPF 在 JPG 上绘制矩形
- kotlin - 如何在 Kotlin 中随机从 ArrayList 中提取条目?
- r - R:根据另一个表替换一个表中的值
- php - 我想制作一个搜索表单,我可以在其中专门搜索与 Symfony 5 上的另一个实体具有空关系的实体
- python - 将列表转换为字典
- python-3.x - 根据特定列中行值的数据类型拆分熊猫数据框
- python - ActiveModel::UnknownAttributeError: WorkOrder 的未知属性“”
- java - 如何使用 http4k 验证请求来自 Google Cloud Platform 上的 Twilio?
- oauth-2.0 - 如何为 Power BI 正确构建 Clio Power Query 自定义连接器?