Note that there are some explanatory texts on larger screens.

plurals
  1. POxslt transformation links
    primarykey
    data
    text
    <p>I am trying to figure out how to change a html page using an xslt transformation on an xml file, by clicking on an element in the table. I have looked around and couldn't find an answer, here is a simple code and I would like to know how to change the page and display something: I don't think it is necessary for you to read the code except for the the final one, the XSLT. I have added the other sections of the code in case they also need some changing. </p> <p>XSD:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com"&gt; &lt;xs:element name="Table"&gt; &lt;xs:complexType&gt; &lt;xs:sequence maxOccurs="unbounded"&gt; &lt;xs:element ref="Person"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="Person"&gt; &lt;xs:complexType&gt; &lt;xs:all maxOccurs="1"&gt; &lt;xs:element ref="Name"/&gt; &lt;xs:element minOccurs="1" ref="Age"/&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="Name"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="1" ref="theName"/&gt; &lt;xs:element maxOccurs="1" ref="Description"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="theName" type="xs:string"/&gt; &lt;xs:element name="Description" type="xs:string"/&gt; &lt;xs:element abstract="false" name="Age" type="xs:positiveInteger"/&gt; &lt;/xs:schema&gt; </code></pre> <p>So I created two elements, theName and the age. Name is composed of the String TheName and the String Description. Age is just a positiveinteger. Now I created the XML file which just chooses two different People:</p> <p>XML:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="try.xsl"?&gt; &lt;Table xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com try.xsd"&gt; &lt;Person&gt; &lt;Name&gt; &lt;theName&gt;Thomas&lt;/theName&gt; &lt;Description&gt;He is a nice guy&lt;/Description&gt; &lt;/Name&gt; &lt;Age&gt;10&lt;/Age&gt; &lt;/Person&gt; &lt;Person&gt; &lt;Name&gt; &lt;theName&gt;Peter&lt;/theName&gt; &lt;Description&gt;He is good at swimming&lt;/Description&gt; &lt;/Name&gt; &lt;Age&gt;12&lt;/Age&gt; &lt;/Person&gt; &lt;/Table&gt; </code></pre> <p>My transformation now is to make a table with the name of the people in function of there age:</p> <p>XSLT:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ws="http://www.w3schools.com" version="1.0"&gt; &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;table border="2"&gt; &lt;tr bgcolor="red"&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="ws:Table/ws:Person"&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="ws:Name/ws:theName"/&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="ws:Age"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; </code></pre> <p>This is where I need help, how do I display the description of the person if I click on the name of the person. So basically if I click on Thomas I want to display "He is a nice guy", and if I click on Peter I want to display "he is a good swimmer".</p> <pre><code> &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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