I am, by no means, even a good xml programmer. In that I currently have a xml document being imported via http that I need to run through the XSL Transformation to get my needed output.
I've attached the input XML, the XSLT and the current output that I'm getting (which is nothing like expected).
Anybody who is an 'expert' at this stuff ... Your help would be greatly appreciated!
Tags:
so...what exactly is the output supposed to look like?
If it only had one properties node the oout would look like:
<Root>
<Row>
<ProfitCenter>
4000
</ProfitCenter>
<CostCenter \>
<PostingDate>
2015-05-19T00:00:00
</PostingDate>
<JournalEntryType>
Goods Receipt/Invoice Receipt Clearing
</JournalEntryType>
<GLAccount>
500000000002
</GLAccount>
<Period>
5
</Period>
<Balance>
-321.36
</Balance>
</Row>
</Root>
so there seems to be lots of problems with the source document. you're using use the atom namespace for the default namespace which isn't going to work...so first thing....remove
xmlns="http://www.w3.org/2005/Atom" from the source doc.
next, you want to first copy over the data you need.....the xslt has to build the document you want. yours wasn't doing that...hhence all you saw was text. an easy way to do that...is use templates...like so:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
next....the select statement you were using i.e.
select="entry/content/properties", would never find the node. basically this needs to be an xpath that can resolve to your document. there's some free online tools out there....but one that can be used to create valid xpaths for you...is this:
http://xmltoolbox.appspot.com/xpath_generator.html
once you figure out the valid xpath...then the nodes can be found and you can rename them...creating the hierarchy you wwant. after I removed the atom namespace (you could also just add a default namespace as well) , I created the xslt below:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match= "/feed/entry/content[@type='application/xml']/properties">
<row>
<ProfitCenter>
<xsl:value-of select="CPROFITCTR_UUID"/>
</ProfitCenter>
<CostCenter>
<xsl:value-of select="CCOST_CTR_UUID"/>
</CostCenter>
<PostingDate>
<xsl:value-of select="CPOSTING_DATE"/>
</PostingDate>
<JournalEntryType>
<xsl:value-of select="TACCDOCTYPE"/>
</JournalEntryType>
<GLAccount>
<xsl:value-of select="CACC_DOC_UUID"/>
</GLAccount>
<Period>
<xsl:value-of select="CFISCPER"/>
</Period>
<Balance>
<xsl:value-of select="KCBALANCE_CURRCOMP"/>
</Balance>
</row>
</xsl:template>
</xsl:stylesheet>
What if I wanted every properties node set up as a new row, not just one?
I believe that's what the xslt is doing
OK, I see that your xsl works, except, I don't want all the peripheral junk put into my output xml. All I want is a simple xml that look like the attached file that pulls the needed data out of the input document and trashes everything else.
I think this is what you want...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:copy-of select="/feed/entry/content[@type='application/xml']/node()"/>
</xsl:template>
<xsl:template match="/">
<root>
<xsl:for-each select="/feed/entry/content[@type='application/xml']/properties">
<row>
<ProfitCenter>
<xsl:value-of select="CPROFITCTR_UUID"/>
</ProfitCenter>
<CostCenter>
<xsl:value-of select="CCOST_CTR_UUID"/>
</CostCenter>
<PostingDate>
<xsl:value-of select="CPOSTING_DATE"/>
</PostingDate>
<JournalEntryType>
<xsl:value-of select="TACCDOCTYPE"/>
</JournalEntryType>
<GLAccount>
<xsl:value-of select="CACC_DOC_UUID"/>
</GLAccount>
<Period>
<xsl:value-of select="CFISCPER"/>
</Period>
<Balance>
<xsl:value-of select="KCBALANCE_CURRCOMP"/>
</Balance>
</row>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
Perfect! Thank you, kind sir.
you owe me a beer :)
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by