网络编程
位置:首页>> 网络编程>> XML编程>> 实例简析XPath串函数和XSLT(2)

实例简析XPath串函数和XSLT(2)

 来源:互联网 发布时间:2008-09-04 14:16:00 

标签:

XSLT样式表文档 Letter.xsl


<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" indent="yes"/>

<xsl:variable name="NL" select="'&#xA;'" />
<xsl:variable name="Para" select="concat($NL, $NL)" />

<xsl:template match="/">

   <xsl:value-of select="//Date" />
   <xsl:value-of select="$Para" />

To,
<xsl:value-of select="concat(//To/FirstName, ' ', //To/LastName)" />
<xsl:value-of select="$NL" />

<xsl:value-of select="//Address/Line1" />
<xsl:value-of select="$NL" />

<xsl:value-of select="//Address/Line2" />
<xsl:value-of select="$NL" />

<xsl:value-of select="concat(//Address/City, ' ', //Address/State, ' ', //Address/Zip)" />
<xsl:value-of select="$NL" />

<xsl:value-of select="//Address/Country" />
<xsl:value-of select="$Para" />

Regarding: <xsl:value-of select="//Subject" />
<xsl:value-of select="$NL" />

Dear <xsl:if test="starts-with(//Sex, 'M')">Mr. </xsl:if><xsl:if test="starts-with(//Sex, 'F')">Miss </xsl:if>
<xsl:value-of select="concat(//To/FirstName, ' ', //To/LastName)" />,
<xsl:value-of select="$Para" />

<xsl:value-of select="//Text" />
<xsl:value-of select="$Para" />
Sincerely,
<xsl:value-of select="$Para" />
<xsl:value-of select="concat(//Sender/FirstName, ' ', //Sender/LastName)" />
<xsl:value-of select="$NL" />
<xsl:value-of select="//Sender/Title" />
</xsl:template>

</xsl:stylesheet>


  
上面的样式表举例说明了concat和starts-with XPath串函数和怎样在输出文本中增加新行,还有定义和使用变量。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com