Note that there are some explanatory texts on larger screens.

plurals
  1. POxslt - can't access curent node with attribute selector
    text
    copied!<p>I am trying to transform an xml file with xsl stylesheet into html. </p> <p>this is the java</p> <pre><code>TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(classLoader.getResourceAsStream("driving.xsl"))); StreamResult drivingHtml = new StreamResult(new StringWriter()); transformer.transform(new StreamSource(classLoader.getResourceAsStream("driving.xml")), drivingHtml); System.out.println(drivingHtml.getWriter().toString()); </code></pre> <p>this is some of the xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;user xmlns="http://notreal.org/ns1" xmlns:poi="http://notreal2.org/ns2"&gt; &lt;address type="primary"&gt; &lt;street&gt;1031 Court St.&lt;/street&gt; &lt;city&gt;Monhegan, NY&lt;/city&gt; &lt;/address&gt; &lt;address type="secondary"&gt; &lt;street&gt; Elm St.&lt;/street&gt; &lt;/address&gt; </code></pre> <p>this is the xsl:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;User&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Detailed Addresses&lt;/p&gt; &lt;table&gt; &lt;th&gt;Primary&lt;/th&gt; &lt;th&gt;Secondary&lt;/th&gt; &lt;tr&gt; &lt;xsl:apply-templates select="/user/address"/&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="address"&gt; &lt;td&gt; &lt;xsl:value-of select=".[@type='primary']/street" /&gt; &lt;xsl:value-of select=".[@type='secondary']/street" /&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select=".[@type='primary']/city" /&gt; &lt;xsl:value-of select=".[@type='secondary']/city" /&gt; &lt;/td&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>when i run that, i get "cannot compile stylesheet"</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