Xml 为什么此代码没有';不输出任何XSLT
我对XSLT一无所知。所以我试着做一个例子,输出一个元素的值。输出格式为纯文本格式。 这是名为cdcatalog.XML的XML文件:Xml 为什么此代码没有';不输出任何XSLT,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我对XSLT一无所知。所以我试着做一个例子,输出一个元素的值。输出格式为纯文本格式。 这是名为cdcatalog.XML的XML文件: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="catalog.xsl"?> <catalog> <cd> <title>Empire</title>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
<catalog>
<cd>
<title>Empire</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>
<europe_country>Bulgaria</europe_country>
<azia_coutry>China</azia_coutry>
</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
但输出窗口中没有显示任何内容。
我错在哪里?
提前谢谢。- 您需要
遍历目录中的
元素。记住这一点cd
- 您说xsl文件名为
,但xml中的cdcatalog.xsl
是href
catalog.xsl
- 您需要
遍历目录中的
元素。记住这一点cd
- 您说xsl文件名为
,但xml中的cdcatalog.xsl
是href
catalog.xsl
- 您需要
遍历目录中的
元素。记住这一点cd
- 您说xsl文件名为
,但xml中的cdcatalog.xsl
是href
catalog.xsl
- 您需要
遍历目录中的
元素。记住这一点cd
- 您说xsl文件名为
,但xml中的cdcatalog.xsl
是href
catalog.xsl
标题元素)
XSLT样式表
Empire
Hide your heart
如您所见,还有第二个模板与text()
匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:transform>
在线尝试此解决方案
顺便说一句,确保元素的名称一致。名为azia\u coutry
的元素与asia\u coutry
或asia\u country
完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为title
元素)
XSLT样式表
Empire
Hide your heart
如您所见,还有第二个模板与text()
匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:transform>
在线尝试此解决方案
顺便说一句,确保元素的名称一致。名为azia\u coutry
的元素与asia\u coutry
或asia\u country
完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为title
元素)
XSLT样式表
Empire
Hide your heart
如您所见,还有第二个模板与text()
匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:transform>
在线尝试此解决方案
顺便说一句,确保元素的名称一致。名为azia\u coutry
的元素与asia\u coutry
或asia\u country
完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为title
元素)
XSLT样式表
Empire
Hide your heart
如您所见,还有第二个模板与text()
匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:transform>
在线尝试此解决方案
顺便说一句,确保元素的名称一致。一个名为azia\u coutry
的元素与asia\u coutry
或asia\u country
完全不同