A good approach for this task is to add small, single-purpose templates. For example
<OriginalID>13154</OriginalID>
would be created by
<xsl:template match="d:XYZBudgetLinesIDInXYZABCBudgetLines">
<OriginalID><xsl:value-of select="." /></OriginalID>
</xsl:template>
Add one of these templates for every output element you need.
Now all you need to do is create one template that handles the individual atom
elements in the input
<xsl:template match="atom:entry">
<XYZABCBudgetLinesItem>
<xsl:apply-templates select="atom:content/m:properties/*" />
</XYZABCBudgetLinesItem>
</xsl:template>
Note: You need to declare the atom namespace prefix in your XSLT (xmlns:atom="http://www.w3.org/2005/Atom"
) or the template won't match anything. In exchange you can drop that default namespace (xmlns="http://www.w3.org/2005/Atom"
), as you're not really interested in creating atom
elements for your output.
The <xsl:apply-templates select="atom:content/m:properties/*" />
will handle the metadata properties of the <entry>
, appropriately executing all those small single-purpose templates you created.
Finally there should be one template that acts as a starting point:
<xsl:template match="/atom:feed">
<XYZABCBudgetLines>
<xsl:apply-templates select="atom:entry" />
</XYZABCBudgetLines>
</xsl:template>
Last but not least you should add a generic empty template to catch all elements that don't have any specific template assigned:
<xsl:template match="*" />
This way you can suppress nodes you don't want to see in the output.
The following will get you started, you can complete it yourself by adding more templates:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xml:base="https://XYZ.net/_api/"
exclude-result-prefixes="atom m d gml georss"
>
<xsl:template match="/atom:feed">
<XYZABCBudgetLines>
<xsl:apply-templates select="atom:entry" />
</XYZABCBudgetLines>
</xsl:template>
<xsl:template match="atom:entry">
<XYZABCBudgetLinesItem>
<xsl:apply-templates select="atom:content/m:properties/*" />
</XYZABCBudgetLinesItem>
</xsl:template>
<xsl:template match="d:XYZBudgetLinesIDInXYZABCBudgetLines">
<OriginalID><xsl:value-of select="." /></OriginalID>
</xsl:template>
<xsl:template match="*" />
</xsl:stylesheet>
Which will output
<XYZABCBudgetLines>
<XYZABCBudgetLinesItem>
<OriginalID>13154</OriginalID>
</XYZABCBudgetLinesItem>
<XYZABCBudgetLinesItem>
<OriginalID>13155</OriginalID>
</XYZABCBudgetLinesItem>
<XYZABCBudgetLinesItem>
<OriginalID>13156</OriginalID>
</XYZABCBudgetLinesItem>
<XYZABCBudgetLinesItem>
<OriginalID>13157</OriginalID>
</XYZABCBudgetLinesItem>
<XYZABCBudgetLinesItem>
<OriginalID>13158</OriginalID>
</XYZABCBudgetLinesItem>
</XYZABCBudgetLines>