Friday, 26 September 2014

XSLT Document() function result contains unwanted xmlns=""



XSLT gurus,


I have an XSLT that is including an unwanted xmlns="" in the output. I've seen this problem/question asked and answered on this site many times, but I can't seem to get any of the answers to work for what I'm doing. And I have to warn you that I am new to XSLT and not very good at it.


My XSLT collects a set of data from the application that calls it, and then also uses document() to pick up additional data. This all works fine, I just need to get rid of the xmlns=""


the XML called by document() is



<?xml version="1.0" encoding="UTF-8"?><BiExport xmlns="">
<ExportData xmlns:xsd="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU">
<Phone>8885551212</Phone>
<ClientRefCmtSuffix/>
<UDFData>
<DictionaryEntry>
<Key xsi:type="xsd:string">MyCompany Completed Date</Key>
<Value xsi:type="xsd:string">06/24/2013</Value>
</DictionaryEntry>
<DictionaryEntry>
<Key xsi:type="xsd:string">Rush</Key>
<Value xsi:type="xsd:string">0</Value>
</DictionaryEntry>
<DictionaryEntry>
<Key xsi:type="xsd:string">Suffix</Key>
<Value xsi:type="xsd:string">0000000000</Value>
</DictionaryEntry>
</UDFData>
<ReportCreateDate>2014-09-26T15:45:48.83952-07:00</ReportCreateDate>
</ExportData>
</BiExport>


And yes, I know it has <BiExport xmlns="">, no I can't change that, and even when I removed it before applying my XSLT it didn't make any difference.


My XSLT is



<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:bean="http://ift.tt/1qE3Yb8">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />

<xsl:variable name="ReportCreateDate" select="bean:FileEvent/bean:Context[@Id='XPathStep']/bean:Item[@Name='ReportCreateDate']/@Value"/>
<xsl:variable name="PDFFile" select="concat($PDFFilename, '.', $PDFFileExt)"/>
<xsl:variable name="InputFile" select="bean:FileEvent/bean:Context[@Id='XPathStep']/bean:Item[@Name='InputFile']/@Value"/>
<xsl:variable name="PDFFilename" select="bean:FileEvent/bean:Context[@Id='XSLTStep']/bean:Item[@Name='PDFFilename']/@Value"/>
<xsl:variable name="InputFilePath" select="bean:FileEvent/bean:Context[@Id='ArchiveMessageStep']/bean:Item[@Name='ArchiveDirectory']/@Value"/>
<xsl:variable name="InputFileString" select="concat($InputFilePath, '\', $PDFFilename, '.xml')"/>

<xsl:template name="UDFs" match="document($InputFileString)/BiExport/ExportData/UDFData/DictionaryEntry">
<xsl:param name="pKey" select="." />
<Item name="{$pKey}">
<xsl:value-of select="../Value"/>
</Item>
</xsl:template>

<xsl:template match="/">
<MDXPackage version="1.0" xmlns="http://ift.tt/1vbHzbt">
<Payload>
<PayloadContext>

<xsl:apply-templates select="document($InputFileString)/BiExport/ExportData/UDFData/DictionaryEntry/Key" />

<xsl:choose>
<xsl:when test="string($ReportCreateDate)">
<Item name="ReportCreateDate">
<xsl:value-of select="$ReportCreateDate"/>
</Item>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>

<xsl:choose>
<xsl:when test="string($PDFFile)">
<Item name="PDFFile">
<xsl:value-of select="$PDFFile"/>
</Item>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
<!-- more of the same follows-->

</PayloadContext>
</Payload>
</MDXPackage>
</xsl:template>
</xsl:stylesheet>


And the output is



<MDXPackage xmlns="http://ift.tt/1qE40zM" version="1.0">
<Payload>
<PayloadContext>
<Item xmlns="" name="MyCompany Completed Date">06/24/2013</Item>
<Item xmlns="" name="Rush">0</Item>
<Item xmlns="" name="Suffix">0000000000</Item>
<Item name="ReportCreateDate">2014-09-26T13:53:28.3831684-07:00</Item>
<Item name="ClaimantPhone">8885551212</Item>
</PayloadContext>
</Payload>
</MDXPackage>


Thanks in advance for any help in understanding why I get the empty namespace declaration and how to get rid of it.


DL


No comments:

Post a Comment