2017-02-28 7 views
0

テキストファイルに変換する必要がある次のXMLコードがあります。私はXSLTのネームスペースで大規模に苦労しています。私はエクスポート/レコードと単純なデフォルト名前空間のマッチングに慣れています。私は、次のXMLコードを持っている:xmlからのXSLTテンプレートマッチング

<?xml version="1.0" encoding="utf-8"?> 
<ArrayOfPerson xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MultiCountryIntegrationService.Core.Entities.Dto"> 
    <Person> 
     <Addresses> 
      <Address> 
       <City>London</City> 
       <Country>GB</Country> 
       <County>London</County> 
       <CreatedDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System"> 
        <d5p1:DateTime>2017-02-21T11:05:08.8387752Z</d5p1:DateTime> 
        <d5p1:OffsetMinutes>0</d5p1:OffsetMinutes> 
       </CreatedDate> 
       <DeletedDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" i:nil="true" /> 
       <EndDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" i:nil="true" /> 
       <Extension i:nil="true" /> 
       <Id>8e5b30d0</Id> 
       <ModifiedDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" i:nil="true" /> 
       <Number>8</Number> 
       <StartDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System"> 
        <d5p1:DateTime>2016-06-30T22:00:00Z</d5p1:DateTime> 
        <d5p1:OffsetMinutes>120</d5p1:OffsetMinutes> 
       </StartDate> 
       <Street>Somewhere</Street> 
       <Type>Primary</Type> 
       <ZipCode>L1 1LL</ZipCode> 
      </Address> 
     </Addresses> 
     <PersonLocalReferences xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> 
    </Person> 
    <Person> 
     <Addresses> 
      <Address> 
       <City>Birmingham</City> 
       <Country>ETC...</Country> 
      </Address> 
     </Addresses> 
     <PersonLocalReferences xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> 
    </Person> 
</ArrayOfPerson> 

マイXSLT - あなたは、私がグーグルとstackoverflowの上で数え切れないほどの時間を行って、いくつかのアプローチを試みた見ることができるように。 i:xmlnsをXMLから削除しても、スタイルシートが機能するようになりますが、XMLを変更する立場にはありません。 Visual Studio 2016を使用してxsltを作成して実行しています。 "@* | node()"を使用すると、すべてが得られ、特定のビットの情報をテキストファイルに出力したいだけです。

以下のxsltを実行すると、ヘッダーとEOFが表示されるだけなので、<xsl:apply-templates select="ArrayOfPerson/Person"/>は適切なレベルのデータを選択していないようです。マイケルは彼のコメントに書いたように

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:i="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="i"> 

    <xsl:output omit-xml-declaration="yes" /> 

    <xsl:template match="/"> 
     <xsl:call-template name="header" /> 

     <xsl:text>Person</xsl:text> 
     <xsl:apply-templates select="ArrayOfPerson/Person"/> 

     <xsl:value-of select="$newline" /> 
     <xsl:text>EOF</xsl:text> 
    </xsl:template> 

    <xsl:template match="Person"> 
     <xsl:value-of select="ArrayOfPerson/Person/Addresses/Address/City"/> 
     <xsl:value-of select="Person/Addresses/Address/City"/> 
     <xsl:value-of select="Addresses/Address/City"/> 
     <xsl:value-of select="."/> 
     <xsl:value-of select="$newline" /> 
     <xsl:text>match</xsl:text> 
     <xsl:value-of select="$newline" /> 
    </xsl:template> 
</xsl:stylesheet> 
+0

あなたは質問にxslt 2.0というタグを付けました。あなたのスタイルシートにはversion = "2.0"と書かれていますが、あなたはVisual Studio 2016を使っていると言います。これは、xpath-default-namespace属性を使用できるかどうかに影響します。 –

+0

「XSLTデフォルトネームスペース」を検索すると、この質問に対する千の回答が見つかります。 ArrayOfPersonは名前空間にありますが、名前空間のないArrayOfPersonを選択しています。 –

+0

情報ありがとうございます。私は、Visual Studioがv2.0を実行できなかったことが、私が得ている他のいくつかのエラーには意味をなさないことを認識していませんでした。 – Itsallgonepearshaped

答えて

0

、あなたのXSLにxpath-default-namespace="http://schemas.datacontract.org/2004/07/MultiCountryIntegrationService.Core.Entities.Dto" を追加:スタイルシートのタグを。

フル名前空間を含める必要があります。