Latest web development tutorials

XSLT <XSL: ค่าของ> องค์ประกอบ

คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง

ความหมายและการใช้งาน

<xsl: ค่าของ> องค์ประกอบสามารถดึงค่าของโหนดที่เลือก

<xsl: ค่าของ> องค์ประกอบที่สามารถนำมาใช้เพื่อเลือกค่าขององค์ประกอบ XML และเอาท์พุทมัน


ไวยากรณ์

<xsl:value-of select="expression" disable-output-escaping="yes|no" />

คุณสมบัติ

属性 描述
select expression 必需。一个 XPath 表达式,规定了从哪个节点/属性来提取值。它的工作原理与通过正斜杠(/)选择子目录的导航文件系统类似。
disable-output-escaping yes
no
可选。如果值为 "yes",通过实例化 <xsl:text> 元素生成的文本节点在输出时将不进行任何转义。比如 "<" 将输出为 "<"。如果值为 "no",则 "<" 将输出为 "&lt;"。默认是 "no"。


ตัวอย่าง

ตัวอย่างต่อไปนี้ได้รับค่าแรกชื่อและศิลปินองค์ประกอบและวางไว้ในตาราง:

ตัวอย่างที่ 1

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

ลอง»

ตัวอย่างต่อไปนี้ loops ผ่านแต่ละองค์ประกอบซีดีและสร้างตารางที่มีแถวสำหรับแต่ละองค์ประกอบซีดีชื่อและศิลปินของค่า:

ตัวอย่างที่ 2

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

ลอง»


คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง คู่มือการใช้งาน XSLT องค์ประกอบอ้างอิง