【发布时间】:2018-05-16 07:09:07
【问题描述】:
我目前正在查看我们有一个样式表要处理的 XML 代码。
我的代码如下所示
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-model href="register_tool/rules/rules.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<addrmap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="register_tool/rules/man_schema.xsd" name="di_do_1430_board" offset="0x0" lsb_size="32">
<enum name="ch_handler_ch_type" bitfield="false">
<element name="be" value="0" offset="0x00000000"/>
</enum>
<addrmap name="be_sys" offset="0x00000000" offset_xpath="addrmap/enum/element[@name='be']/@offset" lsb_size="24">
<ref name="be_reg_acc" path="blocks/be_reg_acc.xml" ref_name="be_reg_acc" offset="0x0" />
</addrmap>
</addrmap>
我的样式表的一部分如下所示
<xsl:choose>
<xsl:when test="@offset_xpath">
<xsl:variable name="resolved_offset"><xsl:evaluate xpath="@offset_xpath"></xsl:evaluate></xsl:variable>
<xsl:apply-templates mode="map">
<xsl:with-param name="offset" select="rdt:all2dec($resolved_offset)"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="map">
<xsl:with-param name="offset" select="rdt:all2dec(@offset)"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
我试图从我的 enum(ch_handler_ch_type) 中获取值,但使用上面的表达式 xsl:evaluate 只给了我#document/fragment 我无法弄清楚如何获取特定值
我正在使用 Saxon-EE 9.8.0.8
问候
编辑
我已将 xi:include 替换为 enum 以更清楚地了解文件的外观。我的目标是 offset_xpath 所在的子 addrmap 节点,我需要更改偏移值。 enum 节点中定义的偏移值。
我已经成功地使用
从枚举中获取了值<xsl:variable name="resolved_offset"><xsl:value-of><xsl:evaluate xpath="@offset_xpath" context-item="." as="xs:string"></xsl:evaluate></xsl:value-of></xsl:variable>
现在我只是不知道如何更改节点 addrmap 中的属性值偏移量。
我试着做一个模板
<xsl:template match="@offset[parent::addrmap]">
<xsl:param name="resolved_offset" tunnel="yes"/>
<xsl:attribute name="offset">
<xsl:value-of select="$resolved_offset"/>
</xsl:attribute>
</xsl:template>
我还可以看到它被正确调用,但是没有发生更改
【问题讨论】:
-
请向我们展示上下文(字面意思),如果不知道上下文节点(由例如
xsl:template match或xsl:for-each select定义),我们无法确定xsl:choose或xsl:evaluate是否有意义外部代码已设置。 -
检查
xi:include是否实际被扩展:这取决于设置正确的选项 (-xi) 和使用正确的 XML 解析器。