1
嵌套属性我有布局这样的XML文件:转换XML使用XSLT
<root>
<node>
<descriptors>
<attribute attr="important"/>
</descriptors>
<value>
Some
</value>
<value>
text
</value>
<value>
here.
</value>
<node>
</root>
有许多节点和每一个是通过在descriptors
元素中的元素区分。我需要提取文本,以便我有这样的:
<element>
Sometexthere.
</element>
我有一个XSL转换:
<xsl:template match="//attribute[@attr='important']">
<element>
<xsl:for-each select="../../value">
<xsl:value-of select="." />
</xsl:for-each>
</element>
</xsl:template>
这不是仅仅写在所有文件中的每一个元素node
的value
元素。 我认为我并不真正了解作用域的工作方式(例如.
指向当前元素/节点,但循环中当前元素/节点是什么)。
我该如何解决这个问题?
编辑
我实际的XSL样式表(我转化的docx文件):
<xsl:template match="/">
<order>
<xsl:apply-templates/>
</order>
</xsl:template>
<xsl:template match="/w:document/w:body/w:p[w:pPr/w:pStyle/@w:val='Pealkiri1']">
<name>
<xsl:for-each select="w:t">
<xsl:value-of select="." />
</xsl:for-each>
</name>
</xsl:template>
这产生了相同的结果,但省略了''标记。所以现在它只是文字。很奇怪。 –
j0ntech
你可以发布你的样式表的其余部分吗?我想你错过了'或者搞乱了一个''。 –
我有匹配'/'的模板,但是它只是用我自己的根元素('order')包围文本。 – j0ntech