- - PR -
XSLでのページ内リンクの方法について
1
投稿者 | 投稿内容 | ||||||||
---|---|---|---|---|---|---|---|---|---|
|
投稿日時: 2005-04-28 06:21
現在XMLファイルをXHTMLに変換しているのですが、ひとつのページ内での文書にリンクさせたいのですが、どうしてもうまくいかない(リンクの場所にジャンプしない)ので質問させて頂きました。
現在記述しているXML,XSLは以下の通りです。 XML------------------ <example> <eg name="eg1" heading="1">例文1</eg> <eg name="eg2" heading="2">例文2</eg> <eg name="eg3" heading="3">例文3</eg> </example> XSL------------------ <html><head><title /></head><body> <xsl:apply-templates select="example/eg" mode="link"> <xsl:sort select="@heading"/> </xsl:apply-templates> <xsl:apply-templates select="example/eg" mode="word"> <xsl:sort select="@name"/> </xsl:apply-templates> </body></html></xsl:template> <xsl:template match="word" mode="link"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="concat('#eg', position())"/> </xsl:attribute> <xsl:value-of select="@heading"/> </xsl:element>| </xsl:template> <xsl:template match="eg" mode="eg"> <xsl:element name="a"> <xsl:attribute name="concat('#eg', position())"/> <xsl:value-of select="@heading"/> | </xsl:element> <xsl:apply-templates select="@name"/> <xsl:apply-templates/> <hr /> </xsl:template> --------------------- かなり基本的な事でしょうが自分で調べた範囲では分からなかったので、ご教授の程よろしくお願いします。 [ メッセージ編集済み 編集者: ケイ 編集日時 2005-04-28 06:49 ] | ||||||||
|
投稿日時: 2005-04-28 07:18
<xsl:attribute name="concat('#eg', position())"/>
を <xsl:attribute name="name"> <xsl:value-of select="concat('#eg', position())"/> </xsl:attribute> に変えてみましょう。 ただそんなめんどくさいことしなくても、 <a name="{concat('#eg', position())}"><xsl:value-of select="@heading"/></a> こんぐらいでもリンクはつくれますよ。 xsl:attributeは動的にタグの属性を増やしたり減らしたりするくらいのときにしか使わないです。 | ||||||||
|
投稿日時: 2005-04-28 18:29
Anthyhimeさん、ありがとうございました。お陰で解決致しました。
<xsl:attribute name="name"> というコードが使えたんですね・・・勉強不足でした。 ただ、<xsl:value-of select="concat('#eg', position())"/> の部分は <xsl:value-of select="concat('eg', position())"/> ですよね?一応確認までに・・・
そうでしたか、私の調べた範囲ではリンクは全てxsl:attributeを使っていたので使わないとリンクが貼れないものと思い込んでいました。<a href=""></a>で十分だったんですね。 本当にありがとうございました。 |
1