My source xml is:
<?xml version="1.0" encoding="UTF-8"?>
<PMML version="4.1" xmlns="http://www.dmg.org/PMML-4_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dmg.org/PMML-4_1 pmml-4-1.xsd">
<Header copyright="(C) Copyright IBM Corp. 1989, 2014.">
<Application name="IBM SPSS Statistics 23.0" version="23.0.0.0"/>
</Header>
<GeneralRegressionModel algorithmName="multinomialLogistic" functionName="classification" modelType="multinomialLogistic" targetVariableName="CLASS">
<MiningSchema>
<MiningField missingValueTreatment="asIs" name="CLASS" usageType="predicted"/>
<MiningField missingValueTreatment="asIs" name="ACTIVE_CUSTOMER" usageType="active"/>
<MiningField missingValueTreatment="asIs" name="SEGMENT" usageType="active"/>
</MiningSchema>
<ParameterList>
<Parameter label="Konstanter Term" name="P0000001"/>
<Parameter label="[ACTIVE_CUSTOMER=0]" name="P0000002"/>
<Parameter label="[ACTIVE_CUSTOMER=1]" name="P0000003"/>
<Parameter label="[SEGMENT=0]" name="P00000004"/>
<Parameter label="[SEGMENT=1]" name="P00000005"/>
</ParameterList>
<ParamMatrix>
<PCell beta="-167.307903919999" df="1" parameterName="P0000001" targetCategory="1"/>
<PCell beta="-0.0747629275586869" df="1" parameterName="P0000002" targetCategory="1"/>
<PCell beta="0.409965797830495" df="1" parameterName="P0000003" targetCategory="1"/>
<PCell beta="-1.03190717557433" df="1" parameterName="P0000004" targetCategory="1"/>
<PCell beta="0.904157514089376" df="1" parameterName="P0000005" targetCategory="1"/>
</ParamMatrix>
</GeneralRegressionModel>
</PMML>
My output xml is:
<?xml version="1.0" encoding="utf-8"?>
<Predictors xmlns:ns="some:ns" xmlns:rs="http://www.dmg.org/PMML-4_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Predictor coefficient="-167.307903919999" name="__INTERCEPT__" value=""/>
<Predictor coefficient="-0.0747629275586869" name="ACTIVE_CUSTOMER" value="0"/>
<Predictor coefficient="0.409965797830495" name="ACTIVE_CUSTOMER" value="1"/>
<Predictor coefficient="" name="SEGMENT" value="0"/>
<Predictor coefficient="" name="SEGMENT" value="1"/>
</Predictors>
I could achieve this with the following xslt:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:ns="some:ns" xmlns:rs="http://www.dmg.org/PMML-4_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<xsl:output encoding="utf-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:key match="rs:ParamMatrix/rs:PCell" name="cell" use="@parameterName"/>
<xsl:key match="rs:DataDictionary/rs:DataField" name="dataField" use="@name"/>
<!-- identity transform -->
<xsl:template match="node()|@*">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>
<xsl:template match="rs:GeneralRegressionModel">
<!--MiningSchema-->
<xsl:apply-templates select="rs:MiningSchema"/>
<!--RegressionTable for predicted targetVariable targetCategory-->
<Predictors>
<xsl:apply-templates select="rs:ParameterList/rs:Parameter"/>
</Predictors>
</xsl:template>
<xsl:template match="rs:Parameter[not(contains(@label, '='))][@name='P0000001']">
<Predictor coefficient="{key('cell', @name)/@beta}" name="__INTERCEPT__" value=""/>
</xsl:template>
<xsl:template match="rs:Parameter[not(contains(@label, '='))][@name!='P0000001']">
<Predictor coefficient="{key('cell', @name)/@beta}" name="{@label}" value=""/>
</xsl:template>
<xsl:template match="rs:Parameter[contains(@label, '=')]" name="split">
<Predictor coefficient="{key('cell', @name)/@beta}" name="{substring-after(substring-before(@label,'='),'[')}" value="{substring-before(substring-after(@label,'='),']')}"/>
</xsl:template>
</xsl:transform>
This XSLT works. However, I have 2 issues: 1. at the beginning of the source xml, there is namespace, such as 'xmlns="http://www.dmg.org/PMML-4_1"', could be other value. The whole document uses only this one namespace. Currently in my xslt, I set namespace as fixed value 'xmlns:rs="http://www.dmg.org/PMML-4_1" ', this is not correct. How do I set namespace dynamically in xslt?
- once I set namespace in xslt, it shows up in the output xml as well. How do I remove this namespace from output xml?
If it´s okay, could you please modify my xslt directly to show me the usage?
Many thanks!!!
exclude-result-prefixes="rs". And remove the identity transform template: you're not copying anything from the source XML, and you don't want to copy anything from the source XML - otherwise you'll be copying its namespace too.identity transformis not the identity transform as it does not usexsl:copybut rather only<xsl:apply-templates select="node()|@*"/>. As for the problem about the namespace being dynamic, with an XSLT 2.0 processor you could use*:foo, e.g.<xsl:template match="*:GeneralRegressionModel"><xsl:apply-templates select="*:MiningSchema"/>..., but it agree that this requirement of an arbitrary namespace sounds odd.