【发布时间】:2011-04-08 17:39:05
【问题描述】:
我正在使用 PHP5,我需要将 XML 转换为以下形式:
<item>
<string isNewLine="1" lineNumber="32">some text in new line</string>
<string>, more text</string>
<item>
<string isNewLine="1" lineNumber="33">some text in new line</string>
<string isNewLine="1" lineNumber="34">some text</string>
<string> in the same line</string>
<string isNewLine="1" lineNumber="35">some text in new line</string>
</item>
</item>
变成这样:
<item>
<line lineNumber="32">some text in new line, more text</string>
<item>
<line lineNumber="33">some text in new line</string>
<line lineNumber="34">some text in the same line</string>
<line lineNumber="35">some text in new line</string>
</item>
</item>
如您所见,它已经跨多个“字符串”节点加入了包含的文本。 另请注意,“字符串”节点可以嵌套在任何级别的其他节点中。
将源 xml 转换为目标 xml 的可能解决方案是什么?
谢谢,
【问题讨论】:
-
检查 cmets 到接受的答案,那里的 XSLT 代码仍然存在错误。
-
好问题 (+1)。请参阅我的答案以获取唯一正确的解决方案。您接受的解决方案根本不正确 - 只需运行它并将结果与您真正想要的结果进行比较。
-