这是我到目前为止有:XSLT样式表
< ?xml version="1.0"?>
< xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
< xmlns:g="http://base.google.com/ns/1.0" version="1.0">
< xsl:output method="RSS 2.0"/>
< xsl:template match="Description">
< title>
< /title>
< /xsl:template>
< xsl:template match="Caption">
< description>
< /description>
< /xsl:template>
< xsl:template match="Url>
< link>
< /link>
< /xsl:template>
< xsl:template match="Condition">
< g:condition>
< /g:condition>
< /xsl:template>
< xsl:template match="Picture">
< g:image_link>
< /g:image_link>
< /xsl:template>
< /xsl:stylesheet>
当我尝试使用一个较小的文件,我就可以只用几个项目创建的,我得到这些调试错误:
/Users/subnetfile/Desktop/finalxsltemplate.xslt:4:
parser
error :
error parsing attribute name
< xmlns:g="http://base.google.com/ns/1.0" version="1.0">
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:4:
parser
error :
attributes construct error
< xmlns:g="http://base.google.com/ns/1.0" version="1.0">
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:4:
namespace
error :
Namespace prefix xmlns on g is not defined
< xmlns:g="http://base.google.com/ns/1.0" version="1.0">
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:4:
parser
error :
Couldn't find end of Start Tag g line 4
< xmlns:g="http://base.google.com/ns/1.0" version="1.0">
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:20:
parser
error :
Unescaped '<' not allowed in attributes values
< link>
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:20:
parser
error :
attributes construct error
< link>
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:20:
parser
error :
Couldn't find end of Start Tag template line 19
< link>
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:22:
parser
error :
Opening and ending tag mismatch: stylesheet line 2 and template
< /xsl:template>
^
/Users/subnetfile/Desktop/finalxsltemplate.xslt:24:
parser
error :
Extra content at the end of the document
< xsl:template match="Condition">
^
error
xsltParseStylesheetFile : cannot parse /Users/subnetfile/Desktop/finalxsltemplate.xslt
(null)
是我正确理解这一点,我才真正需要使用“匹配”功能为所有的项目只是有一个不带属性值之类的东西属性的一个子级。
此外,最终产品中的字段需要在原始文件中具有对应的值,或者可以为每个项目插入它们。例如,最终的格式需要一个名为'payment_accepted'的字段,并且没有字段对应,但我只想为每个项目添加相同的值,例如'Visa'。我会不会'匹配',使用'foreach'之类的东西?
编辑:
< xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g="http://base.google.com/ns/1.0"
version="1.0">
< xsl:output method="RSS 2.0"/>
< xsl:template match="*[local-name()='title']">
< xsl:text>title: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="*[local-name()='link']">
< xsl:text>link: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="*[local-name()='description']">
< xsl:text>description: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="language"/> < !-- suppress -->
< /xsl:stylesheet>
这是开始做一些事情,但我需要另一条线索请
编辑:
我已经取得了一些进展,并提出一些正确的做一些事情:
< xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g="http://base.google.com/ns/1.0"
version="1.0">
< xsl:output method="text"/>
< xsl:template match="Description">
< xsl:text>title: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="Url">
< xsl:text>link: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="Caption">
< xsl:text>description: </xsl:text>
< xsl:apply-templates/>
< /xsl:template>
< xsl:template match="language"/> < !-- suppress -->
< /xsl:stylesheet>
这与没有调试错误,它不正是我所需要的,我将如何添加谷歌命名空间属性使用xlmnsg..etc和xml文件中没有对应值的一些属性,就像我只想为每个节点分配相同的g:condition'new'(我是否正确,每个元素在这里被称为节点? )
我真的不明白你的问题。请提供减少输入样本,准确输出它,并说明关系。 – 2011-02-12 14:31:24
@Alejandro:请参阅我的其他类似问题,它是这个 – fightermagethief 2011-02-13 01:37:57