更改 XSLT 中其他兄弟节点之间的节点
make changes to nodes between other sibling nodes in XSLT
我是 xslt 的初学者,非常感谢您对以下问题的帮助。
在节点 <case>
内,我想在其第一个 <beginning>
和第一个 <end>
兄弟节点之间 select <s>
个节点,第二个 <beginning>
和第二个<end>
分别是第 nth 个开始和第 nth 个节点;并向它们添加属性 @attribute:unsolved
。同时,我想完整地保留 xml 文件的其余部分。
我的输入和期望的输出如下所示。非常感谢你的帮助。
XML 输入:
<content>
<issue>1</issue>
<status>to be solved</status>
</content>
<case>
<beginning>problem</beginning>
<s>this</s>
<s>is</s>
<s>a</s>
<s>problem</s>
<end>problem</end>
<s>no</s>
<s>problem</s>
<s>here</s>
<s>.</s>
<beginning>problem</beginning>
<s>problem</s>
<s>again</s>
<end>problem</end>
<s>no</s>
<s>issue</s>
</case>
期望的输出:
<content>
<issue>1</issue>
<status>to be solved</status>
</content>
<case>
<beginning>problem</beginning>
<s attribute='unsolved'>this</s>
<s attribute='unsolved'>is</s>
<s attribute='unsolved'>a</s>
<s attribute='unsolved'>problem</s>
<end>problem</end>
<s>no</s>
<s>problem</s>
<s>here</s>
<s>.</s>
<beginning>problem</beginning>
<s attribute='unsolved'>problem</s>
<s attribute='unsolved'>again</s>
<end>problem</end>
<s>no</s>
<s>issue</s>
</case>
如果我理解你的意思,那么你的 XPath 将显示为:
`//beginning/following::s[./following::end]
[
count(.|//end/following::s[./following::beginning])
!=
count(//end/following::s[./following::beginning])
]`
我是 xslt 的初学者,非常感谢您对以下问题的帮助。
在节点 <case>
内,我想在其第一个 <beginning>
和第一个 <end>
兄弟节点之间 select <s>
个节点,第二个 <beginning>
和第二个<end>
分别是第 nth 个开始和第 nth 个节点;并向它们添加属性 @attribute:unsolved
。同时,我想完整地保留 xml 文件的其余部分。
我的输入和期望的输出如下所示。非常感谢你的帮助。
XML 输入:
<content>
<issue>1</issue>
<status>to be solved</status>
</content>
<case>
<beginning>problem</beginning>
<s>this</s>
<s>is</s>
<s>a</s>
<s>problem</s>
<end>problem</end>
<s>no</s>
<s>problem</s>
<s>here</s>
<s>.</s>
<beginning>problem</beginning>
<s>problem</s>
<s>again</s>
<end>problem</end>
<s>no</s>
<s>issue</s>
</case>
期望的输出:
<content>
<issue>1</issue>
<status>to be solved</status>
</content>
<case>
<beginning>problem</beginning>
<s attribute='unsolved'>this</s>
<s attribute='unsolved'>is</s>
<s attribute='unsolved'>a</s>
<s attribute='unsolved'>problem</s>
<end>problem</end>
<s>no</s>
<s>problem</s>
<s>here</s>
<s>.</s>
<beginning>problem</beginning>
<s attribute='unsolved'>problem</s>
<s attribute='unsolved'>again</s>
<end>problem</end>
<s>no</s>
<s>issue</s>
</case>
如果我理解你的意思,那么你的 XPath 将显示为:
`//beginning/following::s[./following::end]
[
count(.|//end/following::s[./following::beginning])
!=
count(//end/following::s[./following::beginning])
]`