これは私がこれまでに持っているものです:
< ?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)
すべてのアイテムには、属性値などのない属性のサブレベルが1つあるだけなので、「一致」機能を実際に使用するだけでよいことを正しく理解していますか?
また、最終製品のフィールドが元のファイルに対応する値を持つ必要があるか、各アイテムに挿入することができます。たとえば、最終的な形式には「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を使用するGoogle名前空間属性と、xmlファイルに対応する値を持たないいくつかの属性を追加するにはどうすればよいですか?同じ g:condition 'new' を各ノードに (各要素がここでノードと呼ばれることは正しいですか?)