XMLとXSLsample.xml<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="sample.xml" ?>
<feeds> <feed name="aaa">bbbbbb</feed> <feed name="ccc">dddddd</feed> </feeds>
sample.xsl<?xml version="1.0" encoding="Shift_JIS" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
<xsl:template match="/"> <html> <body> <xsl:for-each select="feeds/feed"> <xsl:value-of select="@name" /> : <xsl:value-of select="." /> </xsl:for-each> </body> </html> </xsl:template>
xsl要素外部XSLファイルの読み込みxsl:import xsl:apply-imports xsl:include
ノード/属性の作成xsl:element xsl:attribute xsl:attribute-set xsl:comment xsl:text
ノードのコピーxsl:copy xsl:copy-of
Templateの呼び出しxsl:call-template xsl:apply-template xsl:with-param
値の出力xsl:value-of
条件xsl:if xsl:choose xsl:when xsl:otherwise
繰り返し処理xsl:for-each
空白文字の処理xsl:preserve-space xsl:strip-space
フォーマットxsl:number xsl:decimal-format
非対応の要素の代替xsl:fallback
Tipsxsl:outputの指定方法- XMLを出力するとき
- <xsl:output method="xml" encoding="UTF-8" doctype-system="sample.dtd" />
- htmlを出力するとき
- <xsl:output method="html" encoding="Shift_JIS"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
- textを出力するとき
- <xsl:output method="text" encoding="Shift_JIS" />
改行/スペースの出力方法<xsl:text>をつかって記述する。
改行だったら以下の感じ <xsl:text> </xsl:text>
ただし、空白HTMLに出力する場合には Entityにすることが必要 空白 は 「 」 です。
改行をbrタグに変換<xsl:template name="br-replace"> <xsl:param name="word"/> <xsl:choose> <xsl:when test="contains($word,'
')"> <xsl:value-of select="substring-before($word,'
')"/> <br/> <xsl:call-template name="br-replace"> <xsl:with-param name="word" select="substring-after($word,'
')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$word"/> </xsl:otherwise> </xsl:choose> </xsl:template>
.の文字を/に変換して相対パスを生成<xsl:template name="path"> <xsl:param name="path"/> <xsl:if test="contains($path,'.')"> <xsl:text>../</xsl:text> <xsl:call-template name="path"> <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param> </xsl:call-template> </xsl:if> <xsl:if test="not(contains($path,'.')) and not($path = '')"> <xsl:text>../</xsl:text> </xsl:if> </xsl:template>
test句のサンプル- test="$count > 0"
- test="@errors[. > 0]"
- test="not(@message)"
- test="contains($string,"'quot;)"
- test="not(contains($path,'.')) and not($path = '')"
- test="position() != 1"
- test="@name[.!='']
- test="count(説明) > 0"
|