모드를 사용하여 처리 단계 (<xsl:template match="field" mode="m1">...</xsl:template>
및 <xsl:template match="data"><xsl:apply-templates select="field" mode="m1"/></xsl:template>
)를 구별 할 수 있지만 물론 another.xsl
을 제작하거나 모드를 사용하도록 편집해야합니다.
두 번째로 질문을 XSLT 2.0으로 태그 지정 했으므로 <xsl:next-match/>
을 사용하는 옵션이 있습니다 (http://www.w3.org/TR/xslt20/#element-next-match 참조).
<xsl:stylesheet version="2.0" exclude-result-prefixes="xs"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:include href="test2013080802.xsl"/>
<xsl:output method="html" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html lang="en">
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="data">
<table>
<thead>
<xsl:apply-templates select="field[1]" mode="thead"/>
</thead>
<tbody>
<xsl:apply-templates/>
</tbody>
</table>
<xsl:apply-templates select="." mode="list"/>
</xsl:template>
<xsl:template match="field" mode="thead">
<tr>
<xsl:apply-templates mode="thead"/>
</tr>
</xsl:template>
<xsl:template match="field/*" mode="thead">
<th><xsl:value-of select="local-name()"/></th>
</xsl:template>
<xsl:template match="field">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="field/*">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
하면이 다음 모드가 list
이름을 사용합니다 포함
이 모드로 작업의 당신에게 예를 제공하기 위해, 주요 스타일입니다 :
는
<xsl:stylesheet version="2.0" exclude-result-prefixes="xs"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/" mode="list">
<html lang="en">
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<xsl:apply-templates mode="#current"/>
</body>
</html>
</xsl:template>
<xsl:template match="data" mode="list">
<ul>
<xsl:apply-templates mode="#current"/>
</ul>
</xsl:template>
<xsl:template match="field" mode="list">
<li>
<xsl:apply-templates select="*" mode="#current"/>
</li>
</xsl:template>
<xsl:template match="field/*" mode="list">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
출력은 다음
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<table>
<thead>
<tr>
<th>attr</th>
<th>attr</th>
</tr>
</thead>
<tbody>
<tr>
<td>Attribute 1</td>
<td>Attribute 2</td>
</tr>
</tbody>
</table>
<ul>
<li>Attribute 1, Attribute 2</li>
</ul>
</body>
</html>
입니다
대단히 감사합니다! –