Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get the XSLT select id() function to work successfully
    primarykey
    data
    text
    <p>I'm having trouble getting the id() function to work in my xslt transformation per the example code below and I'm not sure why. When I load data.xml into a browser I'm expecting to see just the name &amp; size values of the 'BC' item per the stylesheet/transformation. Any suggestions? FYI: I've adapted the example from <a href="http://www.java2s.com/Tutorial/XML/0100__XSLT-stylesheet/selectbyid.htm" rel="nofollow">another site</a>.</p> <p>File: transform.xslt</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:output method="html" indent="yes" encoding="UTF-8" /&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;body&gt; &lt;xsl:value-of select="id('BC')/name" /&gt; &lt;xsl:value-of select="id('BC')/size" /&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>File: data.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="transform.xslt" ?&gt; &lt;provinces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="data.xsd"&gt; &lt;province id="AB"&gt; &lt;name&gt;Alberta&lt;/name&gt; &lt;size&gt;33&lt;/size&gt; &lt;/province&gt; &lt;province id="BC"&gt; &lt;name&gt;British Columbia&lt;/name&gt; &lt;size&gt;44&lt;/size&gt; &lt;/province&gt; &lt;province id="MB"&gt; &lt;name&gt;Manitoba&lt;/name&gt; &lt;size&gt;55&lt;/size&gt; &lt;/province&gt; &lt;/provinces&gt; </code></pre> <p>File: data.xsd</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="provinces"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="province" minOccurs="1" maxOccurs="unbounded" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="province"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="name" /&gt; &lt;xs:element name="size" /&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="id" type="xs:ID" use="required"/&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&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. 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