Note that there are some explanatory texts on larger screens.

plurals
  1. POReverse-Engineering unknown XML based on known XSL
    text
    copied!<h2>Solved!</h2> <p>After following Matti's suggestions, I removed the custom functions and all is well.</p> <h2>Original Post:</h2> <p><strong>I'm new to XSLT as of today, so I'm sure this is a no-brainer for many of you. Anyways:</strong></p> <p>I've been tasked with creating a widget for my company's website that uses data provided by a 3rd-party vendor.</p> <p>The vendor refuses to send us a sample XML file (<em>even a blanked-out one with just the element tags!</em>) so I'm trying to recreate the XML based on what I can see in the XSLT that they -did- send us. (<em>ridiculosity abounds</em>)</p> <p><strong>This is the (stripped) XSLT file we were sent:</strong> </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myCustXslFunctions="urn:CustomXslFunctions"&gt; &lt;xsl:variable name="NumberColumns" &gt;1&lt;/xsl:variable&gt; &lt;xsl:variable name="PaperId" &gt;1234567890ABCDEF&lt;/xsl:variable&gt; &lt;xsl:output method="html" version="1.0" encoding="UTF-8" indent="no" /&gt; &lt;xsl:template match="/NewDataSet"&gt; &lt;div&gt;&lt;xsl:apply-templates select="/NewDataSet" mode="columns" /&gt;&lt;/div&gt; &lt;/xsl:template&gt; &lt;xsl:template match="NewDataSet" mode="columns"&gt; &lt;xsl:for-each select="Table[position() mod $NumberColumns = 1 or $NumberColumns = 1]"&gt; &lt;p&gt; &lt;xsl:for-each select=".|following-sibling::Table[position() &amp;lt; $NumberColumns]"&gt; &lt;span class="description"&gt; &lt;xsl:element name="a"&gt; &lt;xsl:attribute name="target"&gt;_blank&lt;/xsl:attribute&gt; &lt;xsl:attribute name="class" &gt;description&lt;/xsl:attribute&gt; &lt;xsl:choose&gt; &lt;xsl:when test="retail='true'"&gt; &lt;xsl:attribute name="href"&gt;http://website/retail/?pid=&lt;xsl:value-of select="$PaperId" /&gt;&amp;#38;adid=&lt;xsl:value-of select="paperitemid" /&gt;&lt;/xsl:attribute&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:attribute name="href"&gt;http://website/?pid=&lt;xsl:value-of select="$PaperId" /&gt;&amp;#38;adid=&lt;xsl:value-of select="paperitemid" /&gt;&lt;/xsl:attribute&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;xsl:choose&gt; &lt;xsl:when test="imageurl != ''"&gt; &lt;xsl:element name="img"&gt; &lt;xsl:attribute name="src"&gt;&lt;xsl:value-of select="imageurl" /&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="border"&gt;0&lt;/xsl:attribute&gt; &lt;xsl:attribute name="class"&gt;thumbnail&lt;/xsl:attribute&gt; &lt;/xsl:element&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:element name="img"&gt; &lt;xsl:attribute name="src"&gt;http://website/thumbs/&lt;xsl:value-of select="paperid" /&gt;_&lt;xsl:value-of select="paperitemid" /&gt;_100.jpg&lt;/xsl:attribute&gt; &lt;xsl:attribute name="border"&gt;0&lt;/xsl:attribute&gt; &lt;xsl:attribute name="class"&gt;thumbnail&lt;/xsl:attribute&gt; &lt;/xsl:element&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:element&gt; &lt;/span&gt; &lt;/xsl:for-each&gt; &lt;/p&gt; &lt;p&gt; &lt;xsl:for-each select=".|following-sibling::Table[position() &amp;lt; $NumberColumns]"&gt; &lt;span class="description"&gt; &lt;xsl:element name="a"&gt; &lt;xsl:attribute name="target"&gt;_blank&lt;/xsl:attribute&gt; &lt;xsl:attribute name="class" &gt;description&lt;/xsl:attribute&gt; &lt;xsl:choose&gt; &lt;xsl:when test="retail='true'"&gt; &lt;xsl:attribute name="href"&gt;http://website/?pid=&lt;xsl:value-of select="$PaperId" /&gt;&amp;#38;adid=&lt;xsl:value-of select="paperitemid" /&gt;&lt;/xsl:attribute&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:attribute name="href"&gt;http://website/?pid=&lt;xsl:value-of select="$PaperId" /&gt;&amp;#38;adid=&lt;xsl:value-of select="paperitemid" /&gt;&lt;/xsl:attribute&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;xsl:choose&gt; &lt;xsl:when test="string-length(shortdescr) = 0"&gt;&lt;xsl:value-of select="myCustXslFunctions:MakeNice(descr,20,20,'Left','true')" /&gt;&lt;/xsl:when&gt; &lt;xsl:otherwise&gt;&lt;xsl:value-of select="myCustXslFunctions:MakeNice(shortdescr,20,20,'Left','true')" /&gt;&lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:element&gt; &lt;/span&gt; &lt;/xsl:for-each&gt; &lt;/p&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:transform&gt; </code></pre> <p><strong>And my feeble attempt at reverse-engineering the XML:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="facepalm.xsl"?&gt; &lt;NewDataSet&gt; &lt;Table&gt; &lt;paperid&gt;123&lt;/paperid&gt; &lt;paperitemid&gt;12345&lt;/paperitemid&gt; &lt;descr&gt;facepalm of doom&lt;/descr&gt; &lt;shortdescr&gt;facepalm&lt;/shortdescr&gt; &lt;retail&gt;true&lt;/retail&gt; &lt;imageurl&gt;http://website/facepalm.jpg&lt;/imageurl&gt; &lt;/Table&gt; &lt;Table&gt; &lt;paperid&gt;456&lt;/paperid&gt; &lt;paperitemid&gt;67890&lt;/paperitemid&gt; &lt;descr&gt;mega-sigh&lt;/descr&gt; &lt;shortdescr&gt;sigh&lt;/shortdescr&gt; &lt;retail&gt;true&lt;/retail&gt; &lt;imageurl&gt;http://website/sigh.jpg&lt;/imageurl&gt; &lt;/Table&gt; &lt;/NewDataSet&gt; </code></pre> <p><strong>There's no doubt in my mind that I'm overlooking something simple, but my novice status with XSLT has already made this a multi-hour project.</strong></p> <p>Any help is greatly appreciated.</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