1

My first forray into XSLT. I'm using VS 2012 to create an SSIS package to import XML data into an SQL table using XSLT to flatten some of the XML data. Upon executing the task, the output XML contains extra data that is not formed XML. I'm close, but I'm not sure how to get it right.

I tried to add the files, but I can't seem to get them into this space. . . and I can't add screen shots. I'm hoping after I post the question, I can attach the files. . .

Edit: Pasted Comments:

Input XML file ends like this

</PropertyReports>
</RVSCompleteReport>
</REPORT>
<SEARCH_NAMES ErrorInfo="">
  <SEARCH_NAME>BALLANCE LAMBERT LISA</SEARCH_NAME>
  <SEARCH_NAME>BALLANCELAMBERT LISA</SEARCH_NAME>
  <SEARCH_NAME>BALLANCE-LAMBERT LISA</SEARCH_NAME>
  <SEARCH_NAME>LAMBERT JACK</SEARCH_NAME>
  <SEARCH_NAME>LAMBERT JOHN</SEARCH_NAME>
  <SEARCH_NAME>LAMBERT JOHN AND LISA</SEARCH_NAME>
</SEARCH_NAMES>
</RvsStandardDelivery>

The Search names are being added to the output as unformatted

</RVSCompleteReport> 
</REPORT> 
BALLANCE LAMBERT LISABALLANCELAMBERT LISABALLANCE-LAMBERT 
LISALAMBERT JACKLAMBERT JOHNLAMBERT JOHN AND LISALAMBERT 
JOHN RLAMBERT JOHN R AND LISA

The XSLT is

<xsl:stylesheet version="1.0" xmlns:xsl="w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/> 
  <xsl:template match="RvsStandardDelivery/REPORT">
    <REPORT>
      <xsl:for-each select="RVSCompleteReport">
        <RVSCompleteReport>
          <OrdrNum>
            <xsl:value-of select="ReportInfo/ordernumber"/>
          </OrdrNum>
          <borrowerName>
            <xsl:value-of select="ReportInfo/borrowername"/>
          </borrowerName>
          <PropAdd>
            <xsl:value-of select="ReportInfo/propertyaddress"/>
          </PropAdd>
        </RVSCompleteReport>
      </xsl:for-each>
    </REPORT>
  </xsl:template>
</xsl:stylesheet>
StuartLC
  • 104,537
  • 17
  • 209
  • 285
  • Input XML file ends like this BALLANCE LAMBERT LISA BALLANCELAMBERT LISA BALLANCE-LAMBERT LISA LAMBERT JACK LAMBERT JOHN LAMBERT JOHN AND LISA – user2311555 May 22 '13 at 13:08
  • The Search names are being added to the output as unformatted BALLANCE LAMBERT LISABALLANCELAMBERT LISABALLANCE-LAMBERT LISALAMBERT JACKLAMBERT JOHNLAMBERT JOHN AND LISALAMBERT JOHN RLAMBERT JOHN R AND LISA – user2311555 May 22 '13 at 13:10
  • The XSLT is ' ' – user2311555 May 22 '13 at 13:13
  • This could be the built-in templates processing nodes that you haven't explicitly matched - see [here](http://stackoverflow.com/questions/3360017/why-does-xslt-output-all-text-by-default) and [here](http://www.dpawson.co.uk/xsl/sect2/defaultrule.html). – StuartLC May 22 '13 at 13:16
  • That was it, thanks. The built-in template was adding the extra data. – user2311555 May 22 '13 at 13:29

1 Answers1

0

This is almost certainly because you haven't provided a template for SEARCH_NAMES and the default / built in templates are processed

Dimitre has a nice debugging template you can add to find these unmatched elements in the same post.

In your case, you could capture the spurious element:

<xsl:template match='SEARCH_NAMES'></xsl:template>

But better yet, you could capture the root, and then apply templates systematically (and replacing the for-each with an apply-template):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates select="RvsStandardDelivery/REPORT"></xsl:apply-templates>
  </xsl:template>

  <xsl:template match="REPORT">
    <REPORT>
      <xsl:apply-templates select="RVSCompleteReport"></xsl:apply-templates>
    </REPORT>
  </xsl:template>

  <xsl:template match="RVSCompleteReport">
    <RVSCompleteReport>
      <OrdrNum>
        <xsl:value-of select="ReportInfo/ordernumber"/>
      </OrdrNum>
      <borrowerName>
        <xsl:value-of select="ReportInfo/borrowername"/>
      </borrowerName>
      <PropAdd>
        <xsl:value-of select="ReportInfo/propertyaddress"/>
      </PropAdd>
    </RVSCompleteReport>
  </xsl:template>

</xsl:stylesheet>
Community
  • 1
  • 1
StuartLC
  • 104,537
  • 17
  • 209
  • 285