xslで質問させてください。
以下のようなxmlとxslを作っているのですが、xslの最後のほうで、
sample.xmlの/empList/emp/type/@idの値に応じて、typeList.xmlの/typeList/type/titleの値を取得したくて、
xsl:value-of select="document('typeList.xml')/typeList/type[@id = type/@id]/title/text()" />
と書いていますが、うまくいきません。どうすればいいでしょうか?
-----[sample.xml]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="a.xsl" type="text/xsl"?>
<empList>
<emp>
<type id="1" />
<name>鈴木</name>
<desc>あああ</desc>
</emp>
<emp>
<type id="2" />
<name>田中</name>
<desc>いいい</desc>
</emp>
</empList>
-----[typeList.xml]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="a.xsl" type="text/xsl"?>
<typeList>
<type id="1">
<title>タイプ1</title>
</type>
<type id="2">
<title>タイプ2</title>
</type>
</typeList>
-----[a.xsl]
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
encoding="UTF-8"
omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
media-type="text/html"
/>
<xsl:template match="/">
<html>
<head><title>サンプル</title></head>
<body>
<xsl:apply-templates select="empList/emp" />
</body>
</html>
</xsl:template>
<xsl:template match="emp">
<h2><xsl:value-of select="name/text()" /></h2>
<p>タイプ:<xsl:value-of select="document('typeList.xml')/typeList/type[@id = type/@id]/title/text()" /></p>
<p>メモ:<xsl:value-of select="desc/text()" /></p>
</xsl:template>
</xsl:stylesheet>
No.1ベストアンサー
- 回答日時:
Q3207219-1.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Q3207219-3.xsl" type="text/xsl"?>
<empList>
<emp>
<type id="1" />
<name>鈴木</name>
<desc>あああ</desc>
</emp>
<emp>
<type id="4" />
<name>田中</name>
<desc>いいい</desc>
</emp>
<emp>
<type id="2" />
<name>田中</name>
<desc>いいい</desc>
</emp>
<emp>
<type id="3" />
<name>田中</name>
<desc>いいい</desc>
</emp>
</empList>
Q3207219-2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
スタイルシートここはいらないだろう
<?xml-stylesheet href="a.xsl" type="text/xsl"?>
-->
<typeList>
<type id="2">
<title>タイプ2</title>
</type>
<type id="1">
<title>タイプ1</title>
</type>
<type id="3">
<title>猪突猛進タイプ</title>
</type>
<type id="4">
<title>遠隔操作タイプ</title>
</type>
</typeList>
Q3207219-3.xsl
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
encoding="UTF-8"
omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
media-type="text/html"
/>
<xsl:template match="/">
<html>
<head><title>サンプル</title></head>
<body>
<xsl:apply-templates select="empList/emp" />
</body>
</html>
</xsl:template>
<xsl:template match="emp">
<h2><xsl:value-of select="name/text()" /></h2>
<p>タイプ:
<xsl:call-template name="hoge"><xsl:with-param name="Id" select="type/@id" />
<xsl:with-param name="Id2" select="document('Q3207219-2.xml')/typeList" />
</xsl:call-template>
</p>
<p>メモ:<xsl:value-of select="desc/text()" /></p>
</xsl:template>
<xsl:template name="hoge">
<xsl:param name="Id" />
<xsl:param name="Id2" />
<xsl:for-each select="$Id2/type">
<xsl:if test="$Id = @id">
<xsl:value-of select="title" />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
【後記】
手元のeXtyleとMinefieldで一応きちんと確認しているが,
正直自信がない。
俺は,XSLTを頻繁に書いている人でもないし
どこかで引数や戻り値にノードリストを指定できないとか聞いたような気がするからだ。
(引数に出来ているのはMSXML 6(VB.NET Orcas付属)やGeckoのバージョンが関係して・・・ないか)
(そのため、並び替えた後に処理ができないとか、なんかそういう話があったような。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
スタイルシートを使用したXM...
-
CPUの考え方を教えてください ...
-
XMLで要素が記述された順番に意...
-
4バイトを10進数に変換する方法
-
昔Winnyってありましたけど、あ...
-
東芝のDynabookなのですがアン...
-
同じタグ名の項目取得
-
SNMP リンクダウンとノードダ...
-
VBでXMLを扱えるコントロールは...
-
ルート要素ノードが2個ある場合?
-
xmlファイルが上手にHTMLに変換...
-
C#で使用中のファイルに別のフ...
-
TreeViewに重複する値をセット
-
XMLファイルの作り方がわかりま...
-
XMLウインドウ表示時のエラー
-
VBSでxmlの値を書き換えたい
-
VB.NETで最後フォのフォ...
-
Visual Basic .NET の識別子は...
-
ASPで型宣言
-
PHPでのXMLの編集・削除の方法
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
xmlのテキストにリンクを張りた...
-
XSLTで固定長データファイルを...
-
タグの有無の判定
-
XSLで、XMLの空タグを制御したい。
-
XMLのHTMLへの変換 (初心者)
-
xmlの複数条件で検索
-
XSLでXMLデータをタブ区切りデ...
-
スタイルシートを使用したXM...
-
XSL内でJavaScriptを記述し、Ja...
-
XSL中の改行、タブを無効にした...
-
XSLTにてタグ名を取得する方法
-
XML/XSLについて質問です
-
重複するものを消したい
-
xmlの属性が重複しているのをx...
-
XMLの名前空間をXSLから指定す...
-
XSLで特定のタグだけを出力する...
-
XSLTを使用したXML->XML変換で...
-
うまく表示されない
-
XMLから指定テキストのみを抜き...
-
XMLをXSLTやCSSに変換してHTML...
おすすめ情報