XSLT Transformation

  • I have the following XML document that I am trying to transform to elements:

    <?

    xml version="1.0"?><Report xmlns="BNF" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="BNF https://corepm.acme.com/ReportServer?%2fWF.TestReports%2fBNF&amp;rs%3aCommand=Render&amp;rs%3aFormat=XML&amp;rc%3aSchema=True" Name="BNF"><table1><Detail_Collection><Detail ID="1" Sub_Workgroup="008-Compliance" Workgroup="02-Deal Decisioning" Business_Feature__="19.0.2" Business_Feature="Sample Business Feature" Capability="04.03. Preferred ProductOptions" Capability_Group="04. Sales Management" Workstream="Platform Specific - CF" Approved_Release_Participation="CORE 2007 Release 2 (Enterprise R3.07)" /><Detail ID="4" Sub_Workgroup="009-Credit" Workgroup="05-ELF (Documents)" Business_Feature__="1.6.205" Business_Feature="Another sample business feature" Capability="07.01. Manage Operations" Capability_Group="07. Production" Workstream="DR/ED Rollout" Approved_Release_Participation="Enterprise Release R2.08" /></Detail_Collection></table1></Report>

    The XSLT style sheet that I'm using is:

    <

    xsl:stylesheet

    version="1.0"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" />

    <xsl:template match="/">

    <DetailCollection>

    <xsl:for-each select="/table1/Detail_Collection/Detail">

    <xsl:element name="{name()}">

    <xsl:for-each select="@*">

    <xsl:element name="{name()}">

    <xsl:value-of select="."/>

    </xsl:element>

    </xsl:for-each>

    </xsl:element>

    </xsl:for-each>

    </DetailCollection>

    </xsl:template>

    </

    xsl:stylesheet>

    When I transform the XML file using that style sheet I don't receive any output.  If I remove the Report element from the XML so that the <table1> is the first element, the output is generated as expected.  How do I construct my XSLT style sheet so that the <Report> element is ignored?  The only way that I seem to get output is when that Report element is removed like this:

    <?

    xml version="1.0"?><table1><Detail_Collection><Detail ID="1" Sub_Workgroup="008-Compliance" Workgroup="02-Deal Decisioning" Business_Feature__="19.0.2" Business_Feature="Sample Business Feature" Capability="04.03. Preferred ProductOptions" Capability_Group="04. Sales Management" Workstream="Platform Specific - CF" Approved_Release_Participation="CORE 2007 Release 2 (Enterprise R3.07)" /><Detail ID="4" Sub_Workgroup="009-Credit" Workgroup="05-ELF (Documents)" Business_Feature__="1.6.205" Business_Feature="Another sample business feature" Capability="07.01. Manage Operations" Capability_Group="07. Production" Workstream="DR/ED Rollout" Approved_Release_Participation="Enterprise Release R2.08" /></Detail_Collection></table1>

  • Can you post the statement that you are attempting to use too? This may help us in helping you...



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Can't check this right now, but I'm pretty sure you need to either change the

    <xsl:template match="/">

    to

    <xsl:template match="/Report">

    or change

    <xsl:for-each select="/table1/Detail_Collection/Detail">

    to

    <xsl:for-each select="/Report/table1/Detail_Collection/Detail">

    The match matches the root element, but the table stuff is under an element under the root.


    Greg Walker
    DBA, ExpenseWatch.com

  • Thanks for your help guys.  I tried Greg's approach but no luck.  Here is the DTS script that I am using to call the transformation:

     

    '**********************************************************************

    '  Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

     Dim objXML, objXSL

     Set objXML = CreateObject("Msxml2.DOMDocument.4.0")

     Set objXSL = CreateObject("Msxml2.DOMDocument.4.0")

     

     objXML.async = False

     objXSL.async = False

     

     objXML.load ("c:\bnfRpt.xml")

     objXSL.load ("c:\bnf.xsl")

     obXML.transformNode (objXSL)

     

     'MsgBoxj obXML.transformNode (objXSL)

     Main = DTSTaskExecResult_Success

    End Function

  • Interesting...

    I used the:

    <xsl:for-each select="/Report/table1/Detail_Collection/Detail">

    syntax in XML Notepad against the XML you posted, and everything worked fine, once I removed the reference to the XML schema (https://corepm.acme.com, since that doesn't resolve for me).

    I'm curious now. If you do come up with a fix, can you post it here? I'd be interested in seeing what the problem was.


    Greg Walker
    DBA, ExpenseWatch.com

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply