2016-07-21 8 views
0

私はXMLファイルを持っています。私は外部XMLへのルックアップを実行する必要がある場所を変換しています。私は正しい構造を持っていると信じていますが、まったく同じことを他のところでやっていますが、なんらかの理由でここではうまくいきません。この2つの唯一の違いは、この例では、検索で変換しているxmlファイルのデータを使用しています。この例では、別の外部XMlファイルのデータを使用しています。外部XMLからのXSLルックアップがvbscriptから機能しない

私のxsl:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
         xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
         extension-element-prefixes="msxsl" > 

<xsl:output method="xml" indent="yes" /> 

    <xsl:variable name="materialLookup" select="document('MaterialLookup.xml')/Materials/Material" /> 

    <xsl:template match="Report[@schema='1.0']"> 
     <Job> 
      <Job_Number><xsl:value-of select="DocumentProperties/title"/></Job_Number> 
      <Benchtops> 
      <xsl:for-each select="Item[Type='Benchtop' and Properties/bench_material_brand='Stone' and Properties/granite_supplier='Claytons']" > 
       <xsl:sort select="PageName"/> 
       <Benchtop> 

        <Material><xsl:value-of select="$materialLookup[cmCode = Properties/bench_material_color]/dmCode"/></Material> 
        <Colour><xsl:value-of select="Properties/bench_material_color"/></Colour> 

       </Benchtop> 
      </xsl:for-each> 
      </Benchtops> 
     </Job> 
    </xsl:template> 


</xsl:transform> 

私のXMLは次のとおりです。

<?xml version="1.0"?> 
<Report schema="1.0"> 
    <Item id="91" name="Cabinet"> 
    <Page>1</Page> 
    <PageName>Page 1</PageName> 
    <Type>Benchtop</Type> 
    <SubType>Benchtop</SubType> 
    <Code>Benchtop</Code> 
    <Desc>TOP GT600</Desc> 
    <Label>TOP(91)</Label> 
    <Properties> 
     <top_sequence_letter>91</top_sequence_letter> 
     <bench_material_brand>Stone</bench_material_brand> 
     <bench_material_color>C4-Milano Mist</bench_material_color> 
     <bench_material_finish></bench_material_finish> 
     <top_granite_thickness>40mm</top_granite_thickness> 
     <granite_supplier>Claytons</granite_supplier> 
    <DocumentProperties> 
    <documenttitle>B98582</documenttitle> 
    </DocumentProperties> 
</Report> 

そしてMaterialLookup.xmlのためのXML検索がある:私は私ができるほとんどすべてを試してみました

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<Materials xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Material> 
    <cmCode>C4-Milano Mist</cmCode> 
    <dmCode>MAT01000399</dmCode> 
    <dmDescription>Essa Stone Milano Mist</dmDescription> 
    </Material> 
    <Material> 
    <cmCode>C4-Verona Mist</cmCode> 
    <dmCode>MAT01000382</dmCode> 
    <dmDescription>Essa Stone Verona Mist</dmDescription> 
    </Material> 
    <Material> 
    <cmCode>ES-Arcardia</cmCode> 
    <dmCode>MAT01000211</dmCode> 
    <dmDescription>Smart Stone Arcadia 012501</dmDescription> 
    </Material> 
</Materials> 

私が見落としているのは本当にシンプルなものになるだろうと思っていますが、現時点では私は困惑しています。

答えて

1

current()<xsl:value-of select="$materialLookup[cmCode = current()/Properties/bench_material_color]/dmCode"/>に使用してください。ここで

完全なサンプルがあり、主入力がある

<?xml version="1.0"?> 
<Report schema="1.0"> 
    <Item id="91" name="Cabinet"> 
     <Page>1</Page> 
     <PageName>Page 1</PageName> 
     <Type>Benchtop</Type> 
     <SubType>Benchtop</SubType> 
     <Code>Benchtop</Code> 
     <Desc>TOP GT600</Desc> 
     <Label>TOP(91)</Label> 
     <Properties> 
      <top_sequence_letter>91</top_sequence_letter> 
      <bench_material_brand>Stone</bench_material_brand> 
      <bench_material_color>C4-Milano Mist</bench_material_color> 
      <bench_material_finish></bench_material_finish> 
      <top_granite_thickness>40mm</top_granite_thickness> 
      <granite_supplier>Claytons</granite_supplier> 
      <DocumentProperties> 
       <documenttitle>B98582</documenttitle> 
      </DocumentProperties> 
     </Properties> 
    </Item> 
</Report> 

二次文書が

<?xml version="1.0" encoding="UTF-8"?> 
<Materials xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Material> 
     <cmCode>C4-Milano Mist</cmCode> 
     <dmCode>MAT01000399</dmCode> 
     <dmDescription>Essa Stone Milano Mist</dmDescription> 
    </Material> 
    <Material> 
     <cmCode>C4-Verona Mist</cmCode> 
     <dmCode>MAT01000382</dmCode> 
     <dmDescription>Essa Stone Verona Mist</dmDescription> 
    </Material> 
    <Material> 
     <cmCode>ES-Arcardia</cmCode> 
     <dmCode>MAT01000211</dmCode> 
     <dmDescription>Smart Stone Arcadia 012501</dmDescription> 
    </Material> 
</Materials> 

であると私はスタイルシートを実行したときに私が得る結果は

<?xml version="1.0" encoding="utf-8"?> 
<Job> 
    <Job_Number/> 
    <Benchtops> 
     <Benchtop> 
     <Material>MAT01000399</Material> 
     <Colour>C4-Milano Mist</Colour> 
     </Benchtop> 
    </Benchtops> 
</Job> 

ある

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    extension-element-prefixes="msxsl" > 

    <xsl:output method="xml" indent="yes" /> 

    <xsl:variable name="materialLookup" select="document('test2016072102.xml')/Materials/Material" /> 

    <xsl:template match="Report[@schema='1.0']"> 
     <Job> 
      <Job_Number><xsl:value-of select="DocumentProperties/title"/></Job_Number> 
      <Benchtops> 
       <xsl:for-each select="Item[Type='Benchtop' and Properties/bench_material_brand='Stone' and Properties/granite_supplier='Claytons']" > 
        <xsl:sort select="PageName"/> 
        <Benchtop> 

         <Material><xsl:value-of select="$materialLookup[cmCode = current()/Properties/bench_material_color]/dmCode"/></Material> 
         <Colour><xsl:value-of select="Properties/bench_material_color"/></Colour> 

        </Benchtop> 
       </xsl:for-each> 
      </Benchtops> 
     </Job> 
    </xsl:template> 


</xsl:transform> 
+0

current()をインクルードすると、結果は変わりません。それでも失敗します。 – paularmy42

+0

@ paularmy42、私は完全なサンプルで答えを編集しました、私は参照されたデータが見つかりましたと思います。 –

+0

答えに感謝します。私はあなたがそれらを持っているのと全く同じようにすべてのファイルを再作成しましたが、それでも失敗したので、私はエディタで変換を実行しようとしました。以前はvbscriptを使って変換を行っていましたが、これは失敗しました。私が得るエラーは** allowdocumentfunction constraint違反**です。おそらく、これはxslの問題ではなくVBの問題ですか? – paularmy42

関連する問題