0

これは私がこれまでに持っているものです:

< ?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' を各ノードに (各要素がここでノードと呼ばれることは正しいですか?)

4

1 に答える 1

1

「XSLT スタイルシート」として提供するテキストには、多くの正式なエラーがあります。

  • 開始タグの左山括弧の直後に名前が続きません。

  • 整形式の XML ではありません。

<xmlns:g="http://base.google.com/ns/1.0"

バージョン="1.0">

ここには 2 つのエラーがあります

  • xmlns:g名前空間の接頭辞は予約語「xml」で始まってはならないため、この名前は許可されません。

  • 要素名の後にスペース以外の文字を続けることはできません (この場合は=)。

これは名前空間の宣言のように見え、要素のように見えるものとしてコーディングするべきではありません。

<xsl:template match="Url>
<link>
</link>
</xsl:template>
<xsl:template match="Condition">

属性の値を囲む必要がある 2 番目の引用符matchが欠落しているため、最初の行の最初の引用符と最後の行の最初の引用符の間のすべてが属性値と見なされます ...

これらのエラーがすべて修正され、スタイルシートが次のようになった場合でも:

<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>

このコードはかなり無意味です。ソース XML ファイルを実際に処理するわけではなく、結果の出力に内容を持ち込むことはありません。

コードの記述を開始するための基本的な理解がある場合にのみ、少なくとも簡単な XSLT チュートリアルを読むことをお勧めします。

于 2011-02-11T03:08:21.523 に答える