私は XSLT を初めて使用するので、この質問は少しばかげているかもしれません。誰かがここで何が起こっているのか説明してもらえますか?
簡単な XML ドキュメント (テスト目的のみ) とそのスタイルシートがあります。
<xsl:value-of select="/.">
が後続のすべてのノードを処理する理由がわかりません。「/」をテストしました。という名前のノードのみを選択しますchild
。
また、 を に置き換える/.
と.
、期待される結果が得られます ( という名前のノードの値のみを出力しますchild
)。
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<catalog title= "Catalog">
catalog
<cd price = "10">
<title>
title text
<child>child</child>
</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<year>1985</year>
</cd>
<cd price = "11">
<title>
second title text
<child>second child </child>
</title>
<artist>Bob Dylan2</artist>
<country>USA2</country>
<company>Columbia2</company>
</cd>
</catalog>
スタイルシート:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" media-type="text/html"/>
<xsl:template match="/">
<html>
<head>
<title> <xsl:value-of select="/catalog/@title" /> </title>
</head>
<body>
<xsl:apply-templates select="/catalog/cd/title"/>
</body>
</html>
</xsl:template>
<xsl:template match="child">
<b>
<xsl:value-of select="/.">
</xsl:value-of>
</b>
<br/>
</xsl:template>
</xsl:stylesheet>
そして結果:
title text catalog title text child Bob Dylan USA Columbia 1985 second title text second child Bob Dylan2 USA2 Columbia2
second title text catalog title text child Bob Dylan USA Columbia 1985 second title text second child Bob Dylan2 USA2 Columbia2