如何使用XSLT创建节点(如果它们不存在)?我需要插入节点<节头>下<组>,但如果<组>节点不存在,那么我也需要创建。XSLT:创建节点,如果它不存在?
例如。
输入(基节点存在):
<story>
<group>
<overhead>
<l1>overhead</l1>
</overhead>
<headline>
<l1>headline</l1>
</headline>
</group>
<text>
<lines>
<l1>line</l1>
</lines>
</text>
</story>
输出:
<story>
<group>
<sectionhead />
<overhead>
<l1>overhead</l1>
</overhead>
<headline>
<l1>headline</l1>
</headline>
</group>
<text>
<lines>
<l1>line</l1>
</lines>
</text>
</story>
输入(基节点不存在):
<story>
<text>
<lines>
<l1>line</l1>
</lines>
</text>
</story>
输出:
<story>
<group>
<sectionhead />
</group>
<text>
<lines>
<l1>line</l1>
</lines>
</text>
</story>
< xsl:if test =“not(group)”>'是要走的路。我怀疑,你只是在错误的上下文节点上测试它。 – Tomalak 2011-06-13 11:39:15
好问题,+1。使用最基本,功能强大的XSLT设计模式 - 覆盖身份规则,查看我的答案,获得完整,简短和简单的解决方案。 – 2011-06-13 13:48:57