0

I have several sql statements that produce a list of elements that 'should' be columns in a database but are not. I wish to use these lists to drive transforming an xml file into the same minus various specific children elements that reference those columns. so for example for TABLE WO I have the list: 'NORMDATE','ORIGRATE','ORIGUNITCOST','PREVRATE','PREVUNITCOST'

I wish to transform this:

    <BASE>
<OBJECT>WO</OBJECT>
    <CHILD1>
    <NAME>ONE</NAME>
    </CHILD1>
    <CHILD1>
    <NAME>PREVUNITCOST</NAME>
    </CHILD1>
    <CHILD2>
    <REFNAME>ONE</REFNAME>
    </CHILD2>
    <CHILD2>
    <REFNAME>PREVUNITCOST</REFNAME>
    </CHILD2>
    </BASE>

into this:

    <BASE>
<OBJECT>WO</OBJECT>
    <CHILD1>
    <NAME>ONE</NAME>
    </CHILD1>
    <CHILD2>
    <REFNAME>ONE</REFNAME>
    </CHILD2>
    </BASE>

I'm not sure how to iterate this list which I have to manually prepare to do this - can someone give me a pointer or reference? I assume I use the identity pattern referenced here: [Text]How to remove elements from xml using xslt with stylesheet and xsltproc?

my IntelliJ reports this: Apache Software Foundation (Xalan XSLTC)1.0 I plan on using IntelliJ to transform the data into a usable output file which will be applied later in the target system.

I will not use this in production, but simply to prepare some data that itself will hopefully be usable in my target systems. So this is for a data preparation task.

kishjeff
  • 121
  • 13

1 Answers1

1

If you are using the Xalan-J processor, you should be able to take advantage of the EXSLT str:tokenize() extension function - for example:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="exclude-columns">NORMDATE,ORIGRATE,ORIGUNITCOST,PREVRATE,PREVUNITCOST</xsl:param>

<xsl:template match="/BASE">
    <xsl:copy>
        <xsl:copy-of select="*[not(REFNAME = str:tokenize($exclude-columns, ','))]"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Note that the above assumes all CHILDn elements use a REFNAME element to reference the column. In your example, some use REFNAME and some use NAME.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51