Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Your main problem, based on the XML and XSLT code provided, is that your code doesn't address at all the fact that the elements in the XML document are in a default namespace</strong>.</p> <p>How to process an XML document with a default namespace is a FAQ -- just search the xslt and xpath tags and you'll find numerous good answers.</p> <p><strong>Here is one possible solution</strong>:</p> <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://notreal.org/ns1" exclude-result-prefixes="x"&gt; &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/&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;thead&gt; &lt;xsl:apply-templates select="x:address/@type"/&gt; &lt;/thead&gt; &lt;tr&gt; &lt;xsl:apply-templates select="x:address/x:street"/&gt; &lt;/tr&gt; &lt;tr&gt; &lt;xsl:apply-templates select="x:address/x:city"/&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@type"&gt; &lt;th&gt;&lt;xsl:value-of select="."/&gt;&lt;/th&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:address/*"&gt; &lt;td&gt;&lt;xsl:value-of select="."/&gt;&lt;/td&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on a complete and well-formed XML document that includes the XML fragment provided in the question</strong>:</p> <pre><code>&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;203 Elm St.&lt;/street&gt; &lt;city&gt;Pittsburgh, PA&lt;/city&gt; &lt;/address&gt; &lt;/user&gt; </code></pre> <p><strong>produces (what seems to be) the wanted, correct result</strong>:</p> <pre><code>&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;thead&gt; &lt;th&gt;primary&lt;/th&gt; &lt;th&gt;secondary&lt;/th&gt; &lt;/thead&gt; &lt;tr&gt; &lt;td&gt;1031 Court St.&lt;/td&gt; &lt;td&gt;203 Elm St.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Monhegan, NY&lt;/td&gt; &lt;td&gt;Pittsburgh, PA&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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