中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

XMLってなぁに?(第16回)

 

こんどはAタグの方を文字実体参照に変更してみよう

a.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
 <html>
  <head>
   <title>TITLE</title>
  </head>
  <body>
   ヘッダ
   <xsl:apply-templates />
   フッタ
  </body>
 </html>
</xsl:template>
<xsl:template match="会社">
 &lt;a href="<xsl:value-of select="@link" />"&gt;<xsl:value-of select="." />&lt;/a&gt;
</xsl:template>
</xsl:stylesheet>

a.xslをIEで表示してみよう。今度はうまく表示されるようになった。

ではa.xmlの方を開いて変換結果の確認をする。

結果
ヘッダ <a href="http://example.com">example.com商社</a> フッタ

なんてこった。aタグ自身が文字として表に出てきているじゃないか。
このままではHTMLの属性にリンクを仕込むことが出来なくなってしまう。

この場合に利用できるのはxsl:attribute要素だ。
ひとつ上の要素の属性nameにテキストノードの中身を流し込むことが出来る。

a.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
 <html>
  <head>
   <title>TITLE</title>
  </head>
  <body>
   ヘッダ
   <xsl:apply-templates />
   フッタ
  </body>
 </html>
</xsl:template>
<xsl:template match="会社">
 <a>
  <xsl:attribute name="href">
   <xsl:value-of select="@link" />
  </xsl:attribute>
  <xsl:value-of select="." />
 </a>
</xsl:template>
</xsl:stylesheet>

下の方の会社テンプレートを見てほしい。
このように利用することで、hrefの中身を変更することが出来る。
これで無事

ヘッダ example.com商社 フッタ

と表示されリンクが有効になっていると思う。

今回で基礎編は終了
今回までの内容でXML+XSLTサイトの構築は十分に出来る。

ぜひチャレンジしてほしい

参照:
xsl:attribute XSLT1.0 7.1.3 xsl:attribute を用いたアトリビュートの生成

投稿日時 : 2004年10月19日 23:39

コメントを追加

# gQvoTfNVYebDqMcSiT 2011/09/29 7:12 http://oemfinder.com

xlhlhG The author deserves for the monument:D

# KMIyfHNYKpqFLjzp 2011/10/06 0:08 http://www.cpc-software.com/

It`s really useful! Looking through the Internet you can mostly observe watered down information, something like bla bla bla, but not here to my deep surprise. It makes me happy..!

# foAZmQCjYsDpoS 2011/10/06 1:25 http://www.cpc-software.com/products/Download-Auto

Unbelievable. Class..!

# dCFiOEiSbLNoEcLfHv 2011/10/18 16:53 http://www.cpc-software.com/products/Download-Micr

Comrade kill yourself.

# JbbVzREnyr 2011/10/18 17:28 http://www.best-software.net/vend-name/adobe

Yeah? I read and I understand that I do not understand anything what it is about:D

# nFosKLCUFQmC 2011/10/18 18:56 http://www.zexersoft.com/download/oem-Adobe-Photos

Author, keep doing in the same way..!

# kVorCEyZkS 2011/11/02 5:19 http://www.pharmaciecambier.com/

I must admit, the webmaster is a cool guy..!

# hEWqHJAJlqI 2011/11/07 19:29 http://www.disfuncion-erectil.org

I read and feel at home. Thanks the creators for a good resource..!

# bfwPGRktUIjMIMe 2011/11/07 19:56 http://www.farmaciaunica.com/

Author, Shoot yourself a knee..!

# hGzAiaXRQsruB 2011/11/08 16:11 http://puissantaphrodisiaque.com

Honestly, not bad news!...

# zVlBayAARb 2011/11/15 3:44 http://www.pharmaciedelange.com/

Hello! How do you feel about young composers?!...

# aIIPpCziyxcbz 2011/11/16 3:50 http://www.laurenslinens.com/

Very amusing thoughts, well told, everything is in its place:D

# cnjxwsskQNIDIbbo 2012/01/07 7:22 http://www.luckyvitamin.com/c-1751-titanium-sports

The author deserves for the monument:D

# ¥Ð©`¥Ð¥ê©` ¥¢¥¦¥È¥ì¥Ã¥È 2012/11/02 18:18 http://burberry.suppa.jp/

I wanted to say thanks to you for this great read!! I¡¯ve got you bookmarked to see new stuff you post.

タイトル
名前
URL
コメント