Xquery 根据元素类型将文本附加到标记值 [英] Xquery append text to tag values depending of the element type
本文介绍了Xquery 根据元素类型将文本附加到标记值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取一些元素的值,然后需要根据元素添加一些文本,例如:
I need to get the values of some elements and then some text needs to be added depending on the element, for example:
<elementType>a</elementType>
<otherElementType>b</otherElementType>
<elementType>c</elementType>
<elementType>d</elementType>
$doc//*[self::elementType or self::otherElementType]/string()
"a"
"b"
"c"
"d"
这会返回值,但我不知道如何获取这样的值:
this returns the values but I don´t know how to get the values like this:
"a is an elementType"
"b is an otherElementType"
"c is an elementType"
"d is an elementType"
推荐答案
您可能希望查看 XSLT 及其基于规则的处理,这似乎与您考虑需求的方式相匹配:
You might like to look at XSLT with its rule-based processing, which seems to match the way you are thinking about your requirements:
使用
<xsl:apply-templates select="*"/>
处理所有元素,然后分开模板规则来说明每种元素如何处理:
to process all the elements, and then separate template rules to say how each kind of element is to be processed:
<xsl:template match="elementType">
do one thing
</xsl:template>
<xsl:template match="otherElementType">
do a different thing
</xsl:template>
这篇关于Xquery 根据元素类型将文本附加到标记值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文