关于的用法

yoken 2003-08-25 05:15:06
authors.xml

<?xml version="1.0"?>
<authors>
<author id="0">
<name lang="Eng">Mike Galos</name>
<nationality>French</nationality>
</author>
<author id="1" period="modern">
aaa
<name>Eva Corets</name>
<nationality>British</nationality>
</author>
<author id="2" period="modern">
<name>Cynthia Randall</name>
<nationality>Canadian</nationality>
</author>
<author id="3">
<name>Stefan Knorr</name>
<nationality>Canadian</nationality>
</author>
<author id="4" period="contemporary">
<name>Paula Thurman</name>
<nationality>British</nationality>
</author>
</authors>




test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/authors/author/name">
<xsl:copy>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>



xmlspy中transform的结果

<?xml version="1.0" encoding="UTF-8"?><name/>French
aaa
<name/>British<name/>Canadian<name/>Canadian<name/>British


为什么结果中还有nationality的内容
如何使结果中<name>带有其原来的值,如 <name>Eva Corets</name>,而非只有<name/>
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
月光易水 2003-08-26
  • 打赏
  • 举报
回复
try:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">
<xsl:apply-templates select="authors/author/name"/>
</xsl:template>

<xsl:template match="name">
<xsl:copy><xsl:value-of select="." /></xsl:copy>
</xsl:template>

</xsl:stylesheet>

:_)
yoken 2003-08-26
  • 打赏
  • 举报
回复
我必须用xsl草案,所以<xsl:copy-of>用不了
用<xsl:copy>怎么做
saucer 2003-08-26
  • 打赏
  • 举报
回复
there is a default template, something like this:

<xsl:template match="*">
<xsl:apply-template select="*" />
</xsl:template>

so if you don't want some elements processed, you need select just the elements you want, like suggested by moonpiazza(月下小生), or filter the element you don't want, nationality, out:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/authors/author/name">
<xsl:copy-of select="." />
</xsl:template>

<xsl:template match="nationality">
</xsl:template>

</xsl:stylesheet>
月光易水 2003-08-25
  • 打赏
  • 举报
回复


1. 匹配模式author自动匹配了其子节点

2. <xsl:copy> Remarks:
The <xsl:copy> element creates a node in the output with the same name, namespace, and type as the current node. Attributes and children are not copied automatically. This element makes identity transformation possible.


try:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" standalone="yes" indent="yes" />

<xsl:template match="/authors/author">
<xsl:apply-templates select="name"/>
</xsl:template>

<xsl:template match="name">
<xsl:copy-of select="." />
</xsl:template>

</xsl:stylesheet>


:_)

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧