如何使用XSL取得一个XML节点的内容,却不取出其下面的子节点的内容(100分)

  • 主题发起人 主题发起人 proman
  • 开始时间 开始时间
P

proman

Unregistered / Unconfirmed
GUEST, unregistred user!
例:
<?xml version="1.0" encoding="UTF-8"?>
<persondata>
<name> aaa
<twoname>bbb</twoname>
<twoname>ccc</twoname>
</name>
</persondata>
我想取出<name>节点的内容,如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title/>
</head>
<body>
<xsl:for-each select="persondata">
<xsl:value-of select="name"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我只想取出aaa,可实际取出的却是 aaa,bbb,ccc.
请问一下,怎么样才能只取我要的节点的内容,却不要这个节点的子节点的内容.
请大家不要对设计上的逻辑怀疑,我现在就是想解决这个问题,我查了很多资料都没有查到这种情况.
谢谢!
 
<?xml version="1.0" encoding="UTF-8"?>
<persondata>
<name> aaa
<twoname>bbb</twoname>
<twoname>ccc</twoname>
</name>
</persondata>
这样写干吗呢?
为什么不把aaa作为属性处理啊
<?xml version="1.0" encoding="UTF-8"?>
<persondata>
<name attribute="aaa">
<twoname>bbb</twoname>
<twoname>ccc</twoname>
</name>
</persondata>
这样就能找到了
 
To:SandWater
我就是想知道在这种结构的情况下如何取得数据.
至于是采用属性还是内容,这是一个复杂的问题不是一句两句话能说清的.
现在的实际情况是我最到了这样的问题,我想知道针对这种情况有没有我不知道的XSL语句可以完成
这样的功能.
 
>>我只想取出aaa,可实际取出的却是 aaa,bbb,ccc.
可以的,用text()函数可以得到你所要的结果。 [:)]
用XMLSPY打开看看便知,语句如下:
--------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title/>
</head>
<body>
<xsl:for-each select="persondata">
<xsl:value-of select="name/text()"/> <!--注意,就是此处-->
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
To Jrq
谢谢你,问题解决,可是我想知道.这个Text()是哪个里面的函数,我查不到啊.
再次感谢!
 
找到了.谢谢,总是好象有点不习惯XSL的处理方式.
Here are some examples of patterns:
para matches any para element
* matches any element
chapter|appendix matches any chapter element and any appendix element
olist/item matches any item element with an olist parent
appendix//para matches any para element with an appendix ancestor element
/ matches the root node
text() matches any text node
processing-instruction() matches any processing instruction
node() matches any node other than an attribute node and the root node
id("W11") matches the element with unique ID W11
para[1] matches any para element that is the first para child element of its parent
*[position()=1 and self::para] matches any para element that is the first child element of its parent
para[last()=1] matches any para element that is the only para child element of its parent
items/item[position()>1] matches any item element that has a items parent and that is not the first item child of its parent
item[position() mod 2 = 1] would be true for any item element that is an odd-numbered item child of its parent.
div[@class="appendix"]//p matches any p element with a div ancestor element that has a class attribute with value appendix
@class matches any class attribute (not any element that has a class attribute)
@* matches any attribute
 
后退
顶部