<?xml-stylesheet type="text/xsl" href="midashi.xsl" ?>
<a><xsl:attribute name="name">code-<xsl:value-of select="code" /></xsl:attribute></a>
とすると、
<a name="code-6758" />
となる(6758はcode要素の値)。
<a><xsl:attribute name="href">#code-<xsl:value-of select="code" /></xsl:attribute><xsl:value-of select="code" /></a>
とすると
<a href="#code-6758">6758</a>
となる。
よくある処理なので、まとめておきます。
<xsl:template match="security"> <xsl:apply-templates select="attribute" /> <xsl:choose> <xsl:when test="position()=last()" /> <xsl:otherwise>,</xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:if test="count(@name)!=0">属性[<xsl:apply-templates select="@name" />]</xsl:if>
XSLTの仕様にmodeという仕様があります。同じ要素名に対して、別のテンプレートを適用したいときに使用するのだと思います。
<xsl:template match="security"> 一覧:<xsl:apply-templates select="code" /> </xsl:template> <xsl:template match="security" mode="detail"> 詳細:<xsl:apply-templates select="code" /> </xsl:template>
と定義しておいて
一覧を表示したいところに <xsl:apply-templates select="security" /> 詳細を表示したいところに <xsl:apply-templates select="security" mode="detail" />
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
transformer.transform( new DOMSource(document), // new StreamResult(System.out)); new StreamResult(new FileOutputStream(new File("hogehoge.xml"))));
この記事は
現在のアクセス:8218