xml - 在 XSLT 属性名称中使用空格
问题描述
我有以下 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<document>
<name>Example</name>
<date>2020-10-31</date>
<level>X_LEGAL_ABC</level>
<bundle>
<b001>E_AT01</b001>
<example_id>00000000000007372165</example_id>
<field>
<field_value>EUR</field_value>
<fieldname>CUR007</fieldname>
</field>
<field>
<field_value>2018-06-30</field_value>
<fieldname>C207</fieldname>
</field>
<field>
<field_value>2014-07-01</field_value>
<fieldname>C206</fieldname>
</field>
</bundle>
<bundle>
<b001>E_AT01</b001>
<example_id>00000000000007372163</example_id>
<field>
<field_value>EUR</field_value>
<fieldname>CUR007</fieldname>
</field>
<field>
<field_value>2020-05-31</field_value>
<fieldname>C207</fieldname>
</field>
<field>
<field_value>2014-06-01</field_value>
<fieldname>C206</fieldname>
</field>
</bundle>
</document>
</root>
使用以下 XSLT 文件:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version='1.1' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<document>
<xsl:attribute name="name"><xsl:value-of select="/root/document/name"/></xsl:attribute>
<xsl:attribute name="date"><xsl:value-of select="/root/document/date"/></xsl:attribute>
<xsl:attribute name="level"><xsl:value-of select="/root/document/level"/></xsl:attribute>
<xsl:for-each select="/root/document/bundle">
<bundle>
<xsl:attribute name="Example_id"><xsl:value-of select="example_id"/></xsl:attribute>
<xsl:attribute name="B001"><xsl:value-of select="B001"/></xsl:attribute>
<xsl:for-each select="./field">
<field>
<xsl:attribute name="FIELDVALUE"><xsl:value-of select="field_value"/></xsl:attribute>
<xsl:attribute name="FIELDNAME"><xsl:value-of select="fieldname"/></xsl:attribute>
</field>
</xsl:for-each>
</bundle>
</xsl:for-each>
</document>
</xsl:template>
</xsl:stylesheet>
这为我提供了一种新的 XML 格式:
<?xml version="1.0" encoding="UTF-8"?>
<document name="Example" date="2020-10-31" level="X_LEGAL_ABC">
<bundle Example_id="00000000000007372165" B001="">
<field FIELDVALUE="EUR" FIELDNAME="CUR007"/>
<field FIELDVALUE="2018-06-30" FIELDNAME="C207"/>
<field FIELDVALUE="2014-07-01" FIELDNAME="C206"/>
</bundle>
<bundle Example_id="00000000000007372163" B001="">
<field FIELDVALUE="EUR" FIELDNAME="CUR007"/>
<field FIELDVALUE="2020-05-31" FIELDNAME="C207"/>
<field FIELDVALUE="2014-06-01" FIELDNAME="C206"/>
</bundle>
</document>
但是,我希望字段字段值显示为字段值。所以中间有一个空格。这可能在 XSLT 文件中吗?
我可以更改:<xsl:attribute name="FIELDVALUE"
变成类似:<xsl:attribute name="FIELD VALUE"
这可能吗?因为如果我尝试运行它,它就不起作用。
我是这个 XSLT 工作的新手,所以任何帮助都将不胜感激。
此致,
迈克尔
解决方案
推荐阅读
- neo4j - Cypher 在列表结构中查找节点而不使用 FOREACH CASE WHEN
- regex - 强密码检查
- javascript - 一直说它期望 dense_Dense1_input 的形状为 [null,8] 但得到的数组形状为 [8,1]
- php - 检索和存储响应(状态码) - PHP
- openpyxl - 如何将单元格填充颜色从一个文档复制到另一个文档?
- xpath - XPath 位置/8 月访问的第二个城市
- node.js - 在父母身上捕获 SIGINT 但无论如何都会杀死孩子
- python - date label on x-axis python format
- influxdb - 错误 403:“通量查询服务已禁用。” 但是在 influxdb.conf 中已经设置了flux-enabled=true
- c++ - 如何修改标准排序算法,以便在单独的数组中跟踪数组中的索引?