2016-05-02 5 views
0

XSLTをVS2012のXSLTデバッガに渡してもうまく動作しますが、.NETコードでXSL変換を正常に実行するのが難しいです。 XSLTデバッガがVS2015で動作しないため、VS2012を使用しています。.NETコードでXslCompiledTransformエラーが発生しましたが、デバッガで変換が機能します

私は「空の文字列は 『』有効な名前ではありません」なXmlExceptionを生成し、次の手順に私のコードをストリップダウンしました

string xsltpath = "switch-onix-tagnames-1.1.xsl"; 
string xmlpath = "Testing.xml"; 
var xct = new System.Xml.Xsl.XslCompiledTransform(true); 
var settings = new XmlWriterSettings(); 

var xtr = new XmlTextReader(xmlpath); 

settings.OmitXmlDeclaration = false; 
settings.ConformanceLevel = ConformanceLevel.Document; 
settings.CloseOutput = false; 

using (var ms = new MemoryStream()) 
{ 
    using (XmlWriter xw = XmlWriter.Create(ms, settings)) 
    { 
     xct.Load(xsltpath); 
     xct.Transform(xtr, xw); 
     Debugger.Break(); 
    } 
} 

「Testing.xml」ファイルは次のとおりです。

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE ONIXmessage SYSTEM "http://www.editeur.org/onix/2.1/short/onix-international.dtd" > 
<ONIXmessage release="2.1"> 
    <header> 
    <m174>Some Publisher</m174> 
    <m175>Some Person 978-999-9999</m175> 
    <m283>[email protected]</m283> 
    <m182>20160226</m182> 
    <m183>Title information from Some Publisher</m183> 
    <m184>eng</m184> 
    <m185>01</m185> 
    <m186>USD</m186> 
    <m187>in</m187> 
    <m193>General Trade</m193> 
    </header> 
    <product> 
    <a001>001001-48747641</a001> 
    <a002>03</a002> 
    <productidentifier> 
     <b221>02</b221> 
     <b244>1433692376</b244> 
    </productidentifier> 
    <productidentifier> 
     <b221>03</b221> 
     <b244>9781433692376</b244> 
    </productidentifier> 
    <productidentifier> 
     <b221>15</b221> 
     <b244>9781433692376</b244> 
    </productidentifier> 
    <b012>DG</b012> 
    <b014>EPUB</b014> 
    <b211>029</b211> 
    <b213>Open Ebook Format</b213> 
    <b214>06</b214> 
    <series> 
     <b018>The Gospel Project</b018> 
    </series> 
    <title> 
     <b202>01</b202> 
     <b203>La Gran Historia, Relatos B&#237;blicos para los m&#225;s peque&#241;os, del Antiguo Testamento</b203> 
    </title> 
    <workidentifier> 
     <b201>15</b201> 
     <b244>9781433692376</b244> 
    </workidentifier> 
    <contributor> 
     <b034>1</b034> 
     <b035>A01</b035> 
     <b047>Some Editorial Staff</b047> 
    </contributor> 
    <contributor> 
     <b034>2</b034> 
     <b035>A12</b035> 
     <b036>Heath McPherson</b036> 
     <b037>McPherson, Heath</b037> 
     <b039>Heath</b039> 
     <b040>McPherson</b040> 
     <b044><![CDATA[<DIV><B>Heath McPherson</B> dirige un peque&ntilde;o estudio art&iacute;stico que produce ilustraciones ingeniosas y animaci&oacute;n para organizaciones en diversas localidades de los Estados Unidos. Su obra incluye <I>Timmy and Tammy&#39;s Train of Thought</I> (El tren del pensamiento de Timmy y Tammy), escrito por Oliver Chin, como as&iacute; tambi&eacute;n varios comerciales animados.<BR /><BR /><B>Heath McPherson</B> runs a small studio that creates whimsical illustrations and animation for folks across the country. His work includes <I>Timmy and Tammy&#39;s Train of Thought</I> by Oliver Chin as well a number of animated commercials.</DIV>]]></b044> 
    </contributor> 
    <b049>by Some Editorial Staff and Heath McPherson</b049> 
    <b058>Spanish Language Edition</b058> 
    <language> 
     <b253>01</b253> 
     <b252>spa</b252> 
    </language> 
    <b061>44</b061> 
    <b064>REL012000</b064> 
    <audience> 
     <b204>01</b204> 
     <b206>02</b206> 
    </audience> 
    <audiencerange> 
     <b074>11</b074> 
     <b075>04</b075> 
     <b076>P</b076> 
    </audiencerange> 
    <audiencerange> 
     <b074>17</b074> 
     <b075>03</b075> 
     <b076>4</b076> 
     <b075>04</b075> 
     <b076>4</b076> 
    </audiencerange> 
    <othertext> 
     <d102>01</d102> 
     <d103>02</d103> 
     <d104><![CDATA[<DIV><I>Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento)<BR /> Presente la Biblia a los aprendices m&aacute;s j&oacute;venes con <I>Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento), edici&oacute;n de cart&oacute;n</I>. Incluye veinte historias del Antiguo Testamento en un nuevo formato interactivo, divertido y atractivo de relatos b&iacute;blicos para los chiquitos que empiezan a caminar.<BR /> Cada historia se caracteriza por ilustraciones en cuatro colores resaltados que, utilizadas en conjunto con la aplicaci&oacute;n &ldquo;B&amp;H Kids AR&rdquo; [realidad aumentada], cobrar&aacute;n vida con im&aacute;genes animadas y la lectura grabada por Jenna Lucado.<BR /> Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento), edici&oacute;n de cart&oacute;n, </I>es el producto m&aacute;s reciente en la familia de libros de <I>Big Picture Interactive</I> &mdash;una serie dise&ntilde;ada para crecer con la familia y fortalecer relaciones en Cristo por medio de publicaciones centradas en la Biblia y difundidas por plataformas m&uacute;ltiples para apasionar a lectores de toda edad.</DIV>]]></d104> 
    </othertext> 
    <othertext> 
     <d102>02</d102> 
     <d103>02</d103> 
     <d104><![CDATA[<DIV><I>Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento)<BR /> Presente la Biblia a los aprendices m&aacute;s j&oacute;venes con <I>Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento), edici&oacute;n de cart&oacute;n</I>. Incluye veinte historias del Antiguo Testamento en un nuevo formato interactivo, divertido y atractivo de relatos b&iacute;blicos para los chiquitos que empiezan a caminar.<BR /> Cada historia se caracteriza por ilustraciones en cuatro colores resaltados que, utilizadas en conjunto con la aplicaci&oacute;n &ldquo;B&amp;H Kids AR&rdquo; [realidad aumentada], cobrar&aacute;n vida con im&aacute;genes animadas y la lectura grabada por Jenna Lucado.<BR /> Historias b&iacute;blicas para los m&aacute;s peque&ntilde;os (Antiguo Testamento), edici&oacute;n de cart&oacute;n, </I>es el producto m&aacute;s reciente en la familia de libros de <I>Big Picture Interactive</I> &mdash;una serie dise&ntilde;ada para crecer con la familia y fortalecer relaciones en Cristo por medio de publicaciones centradas en la Biblia y difundidas por plataformas m&uacute;ltiples para apasionar a lectores de toda edad.<BR /><BR /> The Big Picture Interactive Bible Stories for Toddlers Old Testament<BR /> Introduce early learners to the Bible with <I>The Big Picture Interactive Bible Stories for Toddlers Old Testament Board Book</I>, featuring twenty Old Testament Bible Stories in this fun, interactive and engaging new Bible storybook designed just for toddlers.<BR /> Each story features enhanced four-color illustrations that used in conjunction with the B&amp;H Kids AR [Augmented Reality] app brings the pictures to life with pop-up imaging and read-a-long narration from Jenna Lucado.<BR /><I>The Big Picture Interactive Bible Stories for Toddlers Old Testament Board Book</I> is the latest in the family of <I>Big Picture Interactive</I> books &ndash; a series designed to grow with families and strengthen relationships in Christ through Bible-centered, multi-platform products that engage readers of all ages.<DIV>&#160;</DIV><DIV>&#160;</DIV><DIV>&#160;</DIV></DIV>]]></d104> 
    </othertext> 
    <othertext> 
     <d102>13</d102> 
     <d103>02</d103> 
     <d104><![CDATA[<DIV><B>Heath McPherson</B> dirige un peque&ntilde;o estudio art&iacute;stico que produce ilustraciones ingeniosas y animaci&oacute;n para organizaciones en diversas localidades de los Estados Unidos. Su obra incluye <I>Timmy and Tammy&#39;s Train of Thought</I> (El tren del pensamiento de Timmy y Tammy), escrito por Oliver Chin, como as&iacute; tambi&eacute;n varios comerciales animados.<BR /><BR /><B>Heath McPherson</B> runs a small studio that creates whimsical illustrations and animation for folks across the country. His work includes <I>Timmy and Tammy&#39;s Train of Thought</I> by Oliver Chin as well a number of animated commercials.</DIV>]]></d104> 
    </othertext> 
    <imprint> 
     <b241>01</b241> 
     <b242>Publisher Cloud Imprint Key</b242> 
     <b243>4028300</b243> 
     <b079>Publisher</b079> 
    </imprint> 
    <publisher> 
     <b291>01</b291> 
     <b241>01</b241> 
     <b242>Publisher Cloud Publisher Key</b242> 
     <b243>4028289</b243> 
     <b081>Some Publisher Group</b081> 
    </publisher> 
    <b394>04</b394> 
    <b003>20160201</b003> 
    <b087>2016</b087> 
    <salesrights> 
     <b089>02</b089> 
     <b090>AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW</b090> 
    </salesrights> 
    <measure> 
     <c093>03</c093> 
     <c094>1</c094> 
     <c095>in</c095> 
    </measure> 
    <measure> 
     <c093>03</c093> 
     <c094>25.4</c094> 
     <c095>mm</c095> 
    </measure> 
    <measure> 
     <c093>08</c093> 
     <c094>1.1</c094> 
     <c095>lb</c095> 
    </measure> 
    <measure> 
     <c093>08</c093> 
     <c094>17.6</c094> 
     <c095>oz</c095> 
    </measure> 
    <measure> 
     <c093>08</c093> 
     <c094>498.95</c094> 
     <c095>gr</c095> 
    </measure> 
    <relatedproduct> 
     <h208>13</h208> 
     <productidentifier> 
     <b221>15</b221> 
     <b244>9781433689680</b244> 
     </productidentifier> 
    </relatedproduct> 
    <supplydetail> 
     <j137>Some Publisher</j137> 
     <j268>02</j268> 
     <j269>Y</j269> 
     <j141>IP</j141> 
     <j396>20</j396> 
     <j143>20160201</j143> 
     <j145>30</j145> 
     <price> 
     <j148>01</j148> 
     <discountcoded> 
      <j363>02</j363> 
      <j364>0040</j364> 
     </discountcoded> 
     <j151>9.99</j151> 
     <j152>USD</j152> 
     <j161>20160127</j161> 
     </price> 
    </supplydetail> 
    </product> 
</ONIXmessage> 

とXSLファイルです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:variable name="release" select="/*/@release" /> 

    <xsl:variable name="target"> 
     <xsl:choose> 
      <xsl:when test="/ONIXMessage">short</xsl:when> 

      <xsl:otherwise>reference</xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 

    <xsl:variable name="dtd-url"> 
     http://www.editeur.org/onix/ 
     <xsl:value-of select="$release" /> 

     /
     <xsl:value-of select="$target" /> 

     /onix-international.dtd 
    </xsl:variable> 

    <xsl:output method="xml" doctype-system="{$dtd-url}" /> 

    <xsl:template match="*"> 
     <xsl:variable name="target-name"> 
      <xsl:choose> 
       <xsl:when test="$target='short'"> 
        <xsl:value-of select="@shortname" /> 
       </xsl:when> 

       <xsl:otherwise> 
        <xsl:value-of select="@refname" /> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:variable> 

     <xsl:element name="{$target-name}"> 
      <xsl:copy-of select="@*[not(name()='refname' or name()='shortname')]" /> 

      <xsl:apply-templates select="*|text()" /> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="text()"> 
     <xsl:copy /> 
    </xsl:template> 
</xsl:stylesheet> 

私は現在、.NET 4.6.1を使用していますが、それはトンのようではありません。 o私が使用している.NETのバージョンに違いがあります。

私はここで何かが分かりませんか?私はXMLの専門家ではないので、簡単に私に行ってください!

+0

ワンノート - DTD XMLファイルの先頭にいないです私がイントラネット上にホストし、それを私のHOSTSファイルで指し示すことによって、それを補うことができました。 – Billious

答えて

1

お知らせごxsl:template試合で*入力XML内のすべての要素います。そのテンプレートの中で、一致した要素の属性@shortnameまたは@refnameから取られた名前を持つ新しい要素が作成されます。私の知る限り見ることができるように、XMLでなく、すべての要素が@shortnameまたは@refname属性を持っており、これは、そのような要素により提起される次の例外が処理される原因になります。

空の文字列は「」は有効ではありません名。

少なくとも、どちらか@shortnameまたは@refname属性を持つテンプレートのみプロセス要素ことを確認します。このコードをテストする人のための

<xsl:template match="*[@shortname or @refname]"> 
+0

ありがとう、それは私が探していた回避策です。残念ながら、実際の問題は修正されていないようですが、変換は正常に実行されますが、結果のXMLは元のものとほとんど変わりません。問題は、DTDが適切に読み込まれていないことが原因で、@ショートネームがいずれのノードでも一致していないことが考えられます。私は代わりにXSDを使用しようとしています、うまくいけばそれは違いを生むでしょう。 – Billious

+0

私は変換を実行中にFiddlerを実行しようとしましたが、DTDがまったく読み込まれているという表示はありません。うーん... – Billious

関連する問題