XMLファイルに、XSLスタイルシートを関連づけ。 †<?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> modeの使い方 †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でスペース( )を入れたい †<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text> XSLT変換 †transformer.transform( new DOMSource(document), // new StreamResult(System.out)); new StreamResult(new FileOutputStream(new File("hogehoge.xml")))); この記事は 現在のアクセス:8210 |