xml - 使用 xml-fragment 进行 Xsl 转换
问题描述
我在下面有一个 xml 文件(切得不完整)。
<xml-fragment xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:c16r2="http://schemas.microsoft.com/office/drawing/2015/06/chart">
<c:plotArea>
<c:layout/>
<c:barChart>
<c:barDir val="col"/>
<c:grouping val="clustered"/>
<c:varyColors val="0"/>
<c:ser>
<c:idx val="0"/>
<c:order val="0"/>
<c:tx>
<c:strRef>
<c:f>Feuil1!$A$1</c:f>
<c:strCache>
<c:ptCount val="1"/>
<c:pt idx="0">
<c:v>hahah</c:v>
我想恢复 <c:v> 标记的值。但是这种语法是错误的:
...code...
<xsl:for-each select="c:val/c:numCache/c:pt">
<td><xsl:value-of select="c:v"/></td>
</xsl:for-each>
...code...
我通过使用更简单的标签重新创建 xml 进行了测试,但同样无法解析,因为 xml-fragment 标签会导致所有错误
<xml-fragment xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:c16r2="http://schemas.microsoft.com/office/drawing/2015/06/chart">
<stuff>
<otherStuff>
<collection>stuff1</collection>
</otherStuff>
<otherStuff>
<collection>stuff2</collection>
</otherStuff>
</stuff>
</xml-fragment>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:safe="http://www.esa.int/safe/sentinel-1.0"
xmlns:bar="http://www.bar.org">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Value 1</th>
<th>Value 2</th>
</tr>
<xsl:for-each select="stuff/otherStuff">
<td><xsl:value-of select="collection"/></td>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我有两个问题:
- 如何检索具有此类字符的标签的值?(C:)
- 为什么 xml-fragment 有问题?
提前致谢。
解决方案
对于您需要xsl:template match="/xml-fragment"
或xsl:for-each select="xml-fragment/stuff/otherStuff"
推荐阅读
- python - 如何从命令行 odoo 11 卸载/更新模块
- hibernate - SQLite 数据库在执行 JAR 时没有响应
- python - 为什么 lemmatizer 在某些单词中不起作用?
- java - 如何处理appium中的阻塞页面?
- firebase - 仅使用 Firestore REST API 通过 DOC_ID 获取
- xamarin - Visual Studio 2019 for Mac:调试器无法连接到 iOS 设备
- python - Python3单链表成就问题
- jquery - 获取相对于整个身体的元素的索引数,而不仅仅是相对于最近的父 div
- php - 从php中的两个数组生成所有组合
- html - 悬停按钮无法使用关键帧正确减少