OL Learn

XSLT Transform Gurus?


I hate writing XSLT, mainly because I’m just no good at it. I have an XML data file with a very bad content model, where everything is an attribute instead of a direct value inside a meaningful node.

I’d like to run an XSLT Transform that could turn this:

<token-value-entry token-name="RECIPIENT_CITY">
<token-value-entry token-name="RECIPIENT_STATE">

Into this:


Can any generous soul give me some direction?


Something like this should work, assuming the input data file is valid XML:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="token-value-entry">
    <xsl:element name="{@token-name}">
      <xsl:value-of select="./token-value/value" />

  <xsl:template match="node()|@*">
      <xsl:apply-templates select="@*"/>



Thanks, my solution ended up being more complex, but I did essentially begin with something very close to this!

My solution had to be more complex because the xml itself was more complex than what I posted. But it did blow the dust off of my XSLT.




I appreciate your participation in this forum, just wanted to say that publicly.



If I weren’t past a certain age when blushing becomes impossible, I would… :stuck_out_tongue: