#author("2019-07-22T05:49:29+00:00","","")
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。

***XMLファイルに、XSLスタイルシートを関連づけ。 [#w653b501]
 <?xml-stylesheet type="text/xsl" href="midashi.xsl" ?>


***アンカーをつける [#r50b5f3c]
 <a><xsl:attribute name="name">code-<xsl:value-of select="code" /></xsl:attribute></a>
とすると、
 <a name="code-6758" />
となる(6758はcode要素の値)。

***アンカーへのリンクを張る [#qff645a3]
 <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>
となる。

***繰り返し処理で、最後以外にカンマをつける [#md326f06]
よくある処理なので、まとめておきます。
 <xsl:template match="security">
 	<xsl:apply-templates select="attribute" />
 	<xsl:choose>
 		<xsl:when test="position()=last()" />
 		<xsl:otherwise>,</xsl:otherwise>
 	</xsl:choose>
 </xsl:template>

***○○属性が存在するときのみ、表示する [#x728cc9a]
 <xsl:if test="count(@name)!=0">属性[<xsl:apply-templates select="@name" />]</xsl:if>


***modeの使い方 [#f45edb86]
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でスペース(&nbsp;)を入れたい [#o824c060]
 <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>

*** XSLT変換 [#gd575255]
 transformer.transform(
  new DOMSource(document),
 //	new StreamResult(System.out));
 new StreamResult(new FileOutputStream(new File("hogehoge.xml"))));



----
この記事は
#vote(おもしろかった[3],そうでもない[0])
#vote(おもしろかった[3],そうでもない[1])

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS