html - XSL:对于每个迭代数据
问题描述
我需要在另一个公共 secuanci 中执行循环序列并获取每个人和每个状态的数据,我对代码的问题是它不会迭代我正在传递的数据。当我有空字段时,我在第二个 for-each 中需要帮助,然后我可以使用 Word 内容控件
XML 文件
<?xml version="1.0"?>
<emailList>
<person>
<name>name 1</name>
<email>g@gmail.com</email>
<status>
<active>1</active>
<active>2</active>
<active>3</active>
</status>
</person>
<person>
<name>name 2</name>
<email>n@hotmail.com</email>
<status>
<active>4</active>
<active>5</active>
</status>
</person>
</emailList>
XSL 文件
<xsl:stylesheet version="1.0">
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
<head>
<title>Email Listing</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>E-mail Address</th>
<th>Status</th>
</tr>
<xsl:for-each select="emailList/person">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="email"/></td>
<td>
<xsl:for-each select="emailList/person/status">
<xsl:value-of select="active"/>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
解决方案
您的内部xsl:for-each
将相对于外部的,即选择person
。
试试改成这个...
<xsl:for-each select="status/active">
<xsl:value-of select="."/>
</xsl:for-each>
where.
选择当前节点。
如果你想用逗号分隔值,你可以这样做....
<xsl:for-each select="status/active">
<xsl:if test="position() > 1">,</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
更好的是,升级到 XSLT 2.0 并完全取消它xsl:for-each
。
<td>
<xsl:value-of select="status/active" separator="," />
</td>
推荐阅读
- python-3.x - Python & SQLite:遍历行只选择第一行
- php - 如何让 PHP 包含数据 URI(不打开 allow_url_include)?
- python-3.x - 测试 spark 数据框列是否包含 5 位数字
- python - 创建 Keras 函数
- keycloak - 如何从 3rd 方 IdP 自定义 Keycloak(代理)OpenID 连接端点回调?
- r - 从 R 数据框列中选择值
- c++ - (UE4) UposeableMeshComponent的骨骼变形后如何正确渲染
- dataframe - 如何在 python 中使用雪花连接创建 Spark 数据框?
- html - HTML/CSS 如何将图像/图标与文本放在一起?
- python - 使用 matplotlib 和 seaborn 创建圆形密度图