Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT conversion creating new qnames from elements
    text
    copied!<p>I need to convert a table of data that comes in xml outputs like the following. C1 column 1 c2 column2 etc</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;report&gt; &lt;report_header&gt; &lt;c1&gt;desc&lt;/c1&gt; &lt;c2&gt;prname&lt;/c2&gt; &lt;c3&gt;prnum&lt;/c3&gt; &lt;c4&gt;cdate&lt;/c4&gt; &lt;c5&gt;phase&lt;/c5&gt; &lt;c6&gt;stype&lt;/c6&gt; &lt;c7&gt;status&lt;/c7&gt; &lt;c8&gt;parent&lt;/c8&gt; &lt;c9&gt;location&lt;/c9&gt; &lt;/report_header&gt; &lt;report_row&gt; &lt;c1&gt;&lt;/c1&gt; &lt;c2&gt;IT Project Message Validation&lt;/c2&gt; &lt;c3&gt;IT-0000021&lt;/c3&gt; &lt;c4&gt;12/14/2010 09:56 AM&lt;/c4&gt; &lt;c5&gt;Preparation&lt;/c5&gt; &lt;c6&gt;IT Projects&lt;/c6&gt; &lt;c7&gt;Active&lt;/c7&gt; &lt;c8&gt;IT&lt;/c8&gt; &lt;c9&gt;/IT/BIOMED&lt;/c9&gt; &lt;/report_row&gt; &lt;report_row&gt; &lt;c1&gt;&lt;/c1&gt; &lt;c2&gt;David, Michael John Morning QA Test&lt;/c2&gt; &lt;c3&gt;IT-0000020&lt;/c3&gt; &lt;c4&gt;12/14/2010 08:12 AM&lt;/c4&gt; &lt;c5&gt;Preparation&lt;/c5&gt; &lt;c6&gt;IT Projects&lt;/c6&gt; &lt;c7&gt;Active&lt;/c7&gt; &lt;c8&gt;IT&lt;/c8&gt; &lt;c9&gt;/IT/BIOMED&lt;/c9&gt; &lt;/report_row&gt; &lt;/report&gt; </code></pre> <p>into </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;report&gt; &lt;report_row&gt; &lt;desc&gt;&lt;/desc&gt; &lt;prname&gt;IT Project Message Validation&lt;/prname&gt; &lt;prnum&gt;IT-0000021&lt;/prnum&gt; &lt;cdate&gt;12/14/2010 09:56 AM&lt;/cdate&gt; &lt;phase&gt;Preparation&lt;/phase&gt; &lt;stype&gt;IT Projects&lt;/stype&gt; &lt;status&gt;Active&lt;/status&gt; &lt;parent&gt;IT&lt;/parent&gt; &lt;location&gt;/IT/BIOMED&lt;/location&gt; &lt;/report_row&gt; &lt;report_row&gt; &lt;desc&gt;&lt;/desc&gt; &lt;prname&gt;David, Michael John Morning QA Test&lt;/prname&gt; &lt;prnum&gt;IT-0000020&lt;/prnum&gt; &lt;cdate&gt;12/14/2010 08:12 AM&lt;/cdate&gt; &lt;phase&gt;Preparation&lt;/phase&gt; &lt;stype&gt;IT Projects&lt;/stype&gt; &lt;status&gt;Active&lt;/status&gt; &lt;parent&gt;IT&lt;/parent&gt; &lt;location&gt;/IT/BIOMED&lt;/location&gt; &lt;/report_row&gt; &lt;/report&gt; </code></pre> <p>my current xslt looks like this</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:template match="/"&gt; &lt;report&gt; &lt;xsl:apply-templates select="/report/report_row"/&gt; &lt;/report&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/report/report_row"&gt; &lt;report_row&gt; &lt;xsl:apply-templates select="c1"/&gt; &lt;xsl:apply-templates select="c2"/&gt; &lt;xsl:apply-templates select="c3"/&gt; &lt;xsl:apply-templates select="c4"/&gt; &lt;xsl:apply-templates select="c5"/&gt; &lt;xsl:apply-templates select="c6"/&gt; &lt;xsl:apply-templates select="c7"/&gt; &lt;xsl:apply-templates select="c8"/&gt; &lt;xsl:apply-templates select="c9"/&gt; &lt;/report_row&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c1"&gt; &lt;xsl:element name="{/report/report_header/c1}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c2"&gt; &lt;xsl:element name="{/report/report_header/c2}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c3"&gt; &lt;xsl:element name="{/report/report_header/c3}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c4"&gt; &lt;xsl:element name="{/report/report_header/c4}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c5"&gt; &lt;xsl:element name="{/report/report_header/c5}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c6"&gt; &lt;xsl:element name="{/report/report_header/c6}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c7"&gt; &lt;xsl:element name="{/report/report_header/c7}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c8"&gt; &lt;xsl:element name="{/report/report_header/c8}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="c9"&gt; &lt;xsl:element name="{/report/report_header/c9}"&gt;&lt;xsl:value-of select="current()"/&gt;&lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:transform&gt; </code></pre> <p>My transform works if I assume a maximal number of columns and the column headers can be legal qnames.</p> <p>It started failing when I got more than the 100 limit I had assumed and column headers with spaces in them.</p> <p>How do I create a transform that uses wildcards instead and how do I strip spaces and illegal characters from the column headers to make them legal qnames?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload