我刚刚创建了一个 XSL 转换,我将 Xml 转换为 xHTML 并返回。这是我第一次使用 XSLT。现在我正在构建“后部”一个反向转换,我被卡住了。
简介/概述
因此,基本 XML 包含我要查找的两个节点(片段):
<frag id="10" name="Editable_Fragment" >
<child id="11"></child>
</frag>
<frag id="20" name="Editable_Fragment2">
<child id="21"></child>
</frag>
顺便说一句,这个 XML 中有很多片段,但我只是在寻找“可编辑”的片段!所以我创建了一个这样的 XSLT:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/review-case/review-document/review-channel/content/region/section/frag[@name='Editable_Fragment']/node()"/>
<xsl:apply-templates select="/review-case/review-document/review-channel/content/region/section/frag[@name='Editable_Fragment2']/node()"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
两个节点的内容在富文本编辑器中作为字符串保存在一起!内容如下所示:
<child id="11" name="Editable_Fragment">....data...</child>
<child id="21" name="Editable_Fragment">....data...</child>
在富文本编辑器中,我正在更改两个节点的一些数据,然后我想使用所谓的反向转换来更新数据。
逆向转换问题
带有两个“子”标签的字符串将用于参数mpTransformParameters中的进一步处理。我必须使用这个参数。我知道通过以下 XSLT 代码,我只是用子 id="11" 和子 id="21" 更新 frag id="10"。
我的问题是,如果两者都在字符串中,我如何将更新的 child id="11" 合并回 "frag id=10" 和 child id="21 到 "frag id=20" ?
“反向”XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:param name="mpTransformParameters"/>
<xsl:template match="review-case/review-document/review-channel/content/region/section/frag/child[@name='Editable_Fragment']">
<xsl:value-of select="$mpTransformParameters" disable-output-escaping="yes"/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
非常感谢