我使用升压序列化的持久性,并且由于库没有保存到旧版本的存档/数据结构的构想表示支持,不过,我觉得我给XSLT &根据需要,XPath将新版本转换为旧版本。 (这也是我第一次参与XSLT & XPath/XQuery,因此请原谅任何明显的错误)。但是,我已经完成了大约一半的工作,但似乎无法完成它(这也是我的第一次尝试进入XSLT & XPath/XQuery,请原谅任何明显的错误)。XSLT转换
这里是我的出发XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="7">
<tester class_id="0" tracking_level="0" version="0">
<count>2</count>
<item_version>0</item_version>
<item class_id="2" class_name="CLASS_D" tracking_level="0" version="0">
<A class_id="1" tracking_level="1" version="0" object_id="_0">
<pimpl class_id="3" tracking_level="1" version="0" object_id="_1">
<b>1</b>
</pimpl>
</A>
<pimpl class_id="4" tracking_level="1" version="0" object_id="_2">
<c>2</c>
</pimpl>
</item>
<item class_id="5" class_name="CLASS_E" tracking_level="0" version="0">
<A object_id="_3">
<pimpl class_id_reference="3" object_id="_4">
<b>1</b>
</pimpl>
</A>
<pimpl class_id="6" tracking_level="1" version="0" object_id="_5">
<f>2</f>
</pimpl>
</item>
</tester>
</boost_serialization>
我想要做的,是带有属性CLASS_NAME =“CLASS_E”要像CLASS_NAME =“CLASS_D”的项目改造项目,但我需要离开单独的object_id属性。
这就是我想要的:
<?xml version="1.0" encoding="utf-8"?>
<boost_serialization signature="serialization::archive" version="7">
<tester class_id="0" tracking_level="0" version="0">
<count>2</count>
<item_version>0</item_version>
<item class_id="2" class_name="CLASS_D" tracking_level="0" version="0">
<A class_id="1" tracking_level="1" version="0" object_id="_0">
<pimpl class_id="3" tracking_level="1" version="0" object_id="_1">
<b>1</b>
</pimpl>
</A>
<pimpl class_id="4" tracking_level="1" version="0" object_id="_2">
<c>2</c>
</pimpl>
</item>
<item class_name="CLASS_D" class_id="2" tracking_level="0" version="0">
<A object_id="_3">
<pimpl class_id_reference="3" object_id="_4">
<b>1</b>
</pimpl>
</A>
<pimpl class_id="4" tracking_level="1" version="0" object_id="_5">
<c>2</c>
</pimpl>
</item>
</tester>
</boost_serialization>
这是模板我到目前为止:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" encoding="UTF-8" indent="yes"/>
<!-- identity-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- replace attribute class_name value with another-->
<!-- replace attribute class_id value with another-->
<!-- only on this node!-->
<!-- could call another template to change more nested things-->
<xsl:template match="item/@class_name[. = 'CLASS_E']">
<xsl:attribute name="class_name">CLASS_D</xsl:attribute>
<xsl:attribute name="class_id">2</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
我不知道如何继续编辑项目的子节点我与此行匹配: 因为我需要将“f”节点更改为“c”并将pimpl“class_id”从6更改为4
在此先感谢
谢谢你这么多的详细答复。这有助于为我解决很多问题。 – Jeremy