-2

テーブル内の要素をクリックして、xml ファイルの xslt 変換を使用して html ページを変更する方法を見つけようとしています。周りを見回しましたが、答えが見つかりませんでした。ここに簡単なコードがあります。ページを変更して何かを表示する方法を知りたいです。コードを読む必要はないと思いますが、最後の XSLT です。変更が必要な場合に備えて、コードの他のセクションを追加しました。

XSD:

 <?xml version="1.0" encoding="UTF-8"?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com"
 xmlns="http://www.w3schools.com">

 <xs:element name="Table">
 <xs:complexType>
 <xs:sequence maxOccurs="unbounded">
 <xs:element ref="Person"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 <xs:element name="Person">
 <xs:complexType>
 <xs:all maxOccurs="1">
 <xs:element ref="Name"/>
 <xs:element minOccurs="1" ref="Age"/>
 </xs:all>
 </xs:complexType>
</xs:element>
<xs:element name="Name">
 <xs:complexType>
 <xs:sequence>
 <xs:element maxOccurs="1" ref="theName"/>
 <xs:element maxOccurs="1" ref="Description"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 <xs:element name="theName" type="xs:string"/>
 <xs:element name="Description" type="xs:string"/>
 <xs:element abstract="false" name="Age" type="xs:positiveInteger"/>
 </xs:schema>

そこで、theName と age という 2 つの要素を作成しました。名前は、文字列 TheName と文字列の説明で構成されます。年齢は単なる正の整数です。ここで、2 人の異なる People を選択するだけの XML ファイルを作成しました。

XML:

 <?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/xsl" href="try.xsl"?>
 <Table xmlns="http://www.w3schools.com"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.w3schools.com try.xsd">
 <Person>
 <Name>
 <theName>Thomas</theName>
 <Description>He is a nice guy</Description>
 </Name>
 <Age>10</Age>
 </Person>

 <Person>
 <Name>
 <theName>Peter</theName>
 <Description>He is good at swimming</Description>
 </Name>
 <Age>12</Age>
 </Person>

 </Table>

私の変換は、年齢に応じて人々の名前を含むテーブルを作成することです。

XSLT:

 <?xml version="1.0" encoding="UTF-8"?>

 <xsl:stylesheet

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ws="http://www.w3schools.com"
 version="1.0"> 

 <xsl:template match="/">
 <html>

 <table border="2">
 <tr bgcolor="red">
 <th>Name</th>
 <th>Age</th>
 </tr>
 <xsl:for-each select="ws:Table/ws:Person">
 <tr>

 <td><xsl:value-of select="ws:Name/ws:theName"/></td>
 <td><xsl:value-of select="ws:Age"/></td>

 </tr>
 </xsl:for-each>
 </table>

ここで助けが必要です。人の名前をクリックすると、その人の説明を表示するにはどうすればよいですか。基本的に、トーマスをクリックすると「彼はナイスガイです」と表示され、ピーターをクリックすると「彼は泳ぎが上手です」と表示されます。

 </html>
 </xsl:template>
 </xsl:stylesheet>

ありがとうございました

4

1 に答える 1

0

XSLT スクリプトはテキスト ファイル (この場合は HTML (Web) ページ) を生成し、別のアプリケーション (Web ブラウザー) によって解釈されます。洗練されたインタラクションを備えた動的な Web ページを作成する方法については、CSSJavaScriptのチュートリアルを参照してください。

于 2012-04-21T16:00:33.660 に答える