XML : XLST Identity Template specific elements, exclude everything else

Using the below XML how would I extract only the Address details into a CSV format?

I believe I need to have a style sheet based on the Identity template, though the examples I found are simple and state to the list the elements you want to exclude. Is there a short way to exclude everything except Address and AddressLine?

I am using .NET to process the XLST transformation. The stylesheet I have come up with so far doesn't return anything.

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    <xsl:output method="text" encoding="utf-8" />    <xsl:strip-space elements="*"/>      <xsl:param name="delim" select="','" />    <xsl:param name="quote" select="'&quot;'" />    <xsl:param name="break" select="'&#xa;'" />      <xsl:template match="node()| @*">      <xsl:copy>        <xsl:apply-templates select="node()| @*"/>      </xsl:copy>    </xsl:template>      <xsl:template match="AddressLine" priority="9">      <xsl:value-of select="concat($quote, ., $quote, $delim)"/>    </xsl:template>      <xsl:template match="*" priority="0" />  </xsl:stylesheet>    
  <Sample Version="6" Date="2012-05-11">    <Header>      <CreatedDate>2015-12-02</CreatedDate>      <CreatedTime>10:31:42</CreatedTime>    </Header>    <Message Group="1" Type="1" Protocol="1">      <MessageHeader>        <MessageReferenceNumber>1</MessageReferenceNumber>      </MessageHeader>      <TransactionHeader>        <ReportPeriodStartDate>2002-04-01</ReportPeriodStartDate>        <ReportPeriodEndDate>2015-11-30</ReportPeriodEndDate>      </TransactionHeader>      <Episode>        <Person>          <General>            <Verified Status="02">              <Identifier>001</Identifier>              <PersonName>                <Name>                  <FirstName>Foo</FirstName>                  <Surname>Bar</Surname>                </Name>              </PersonName>              <Address>                <AddressLine></AddressLine>                <AddressLine>Street</AddressLine>                <AddressLine>Town</AddressLine>                <AddressLine>City</AddressLine>              </Address>            </Verified>          </General>        </Person>        <Session>          <Input>            <StartDate>2015-10-31</StartDate>            <StartTime>17:15:00</StartTime>          </Input>          <Output>            <StatusCode>8</StatusCode>            <LocationCode>9</LocationCode>          </Output>        </Session>      </Episode>      <MessageTrailer>        <MessageReferenceNumber>1</MessageReferenceNumber>      </MessageTrailer>    </Message>    <Message Group="1" Type="1" Protocol="1">      <MessageHeader>        <MessageReferenceNumber>2</MessageReferenceNumber>      </MessageHeader>      <TransactionHeader>        <ReportPeriodStartDate>2002-04-01</ReportPeriodStartDate>        <ReportPeriodEndDate>2015-11-30</ReportPeriodEndDate>      </TransactionHeader>      <Episode>        <Person>          <General>            <Verified Status="02">              <Identifier>002</Identifier>              <PersonName>                <Name>                  <FirstName>Foo</FirstName>                  <Surname>Bar</Surname>                </Name>              </PersonName>              <Address>                <AddressLine></AddressLine>                <AddressLine>Street</AddressLine>                <AddressLine>Town</AddressLine>                <AddressLine>City</AddressLine>              </Address>            </Verified>          </General>        </Person>        <Session>          <Input>            <StartDate>2015-10-31</StartDate>            <StartTime>17:15:00</StartTime>          </Input>          <Output>            <StatusCode>8</StatusCode>            <LocationCode>9</LocationCode>          </Output>        </Session>      </Episode>      <MessageTrailer>        <MessageReferenceNumber>2</MessageReferenceNumber>      </MessageTrailer>    </Message>    <Trailer>      <RecordCount>2</RecordCount>    </Trailer>  </Sample>    

No comments:

Post a Comment