這是我到目前爲止有: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