XMLとXSLTの学習を始めたばかりで、Xpathについて簡単な質問があります。
XMLコードは次のとおりです。
<root>
<shop>
<person>
<employee>
<name> Alexis </name>
<role> Manager </role>
<task> Sales </task>
</employee>
</person>
</shop>
<person>
<employee>
<role> Supervisor </role>
<name> Blake </name>
<task> Control </task>
</employee>
</person>
</root>
XSLTコードは次のとおりです。
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html><head></head>
<body><xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="shop">
<xsl:apply-templates select="/root/*/*"/>
</xsl:template>
<xsl:template match="employee">
<u> <xsl:apply-templates select="name"/> </u>
(Task: <xsl:apply-templates select="task"/>)
<br></br>
</xsl:template>
<xsl:template match="person2">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
出力は次のとおりです。
Alexis (Task: Sales )
Blake (Task: Control )
Blake (Task: Control )
私が理解していないのは、なぜ最後の部分が複製されているのですか?XSLTコードのこの部分が原因であることを私は知っています:
<xsl:apply-templates select="/root/*/*"/>
しかし、それは私がコードをいじってFirefoxで表示していたからです。でも理由はわかりません。
私が理解していることから、それは「ルート」のすべての孫要素を次のように選択しています。
ルート/ショップ/人
しかし、なぜアレクシスも繰り返されないのですか?ブレイクだけが繰り返されます...