help在线等待

wangyiyun0119 2003-10-09 04:51:56
哪里有,或者谁能说明一下关于xsl里面的代码的意义
比方说
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
是什么意思
谁能将xsl里面出现的类似的代码说明清楚点,或者介绍一本书来看看
分数不够我就加,立马给分
...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhfkiller 2003-10-10
  • 打赏
  • 举报
回复
xsl:apply-templates Element
Directs the XSLT processor to find the appropriate template to apply, based on the type and context of each selected node.

<xsl:apply-templates select = Expression mode = QName>
</xsl:apply-templates>
Attributes
select
Can be used to process nodes selected by an expression instead of processing all children. The value of the select attribute is an expression. The expression must evaluate to a node-set. The selected set of nodes is processed in document order unless a sorting specification is present.
mode
The mode attribute allows an element to be processed multiple times, each time producing a different result. If <xsl:template> does not have a match attribute, it must not have a mode attribute. If an <xsl:apply-templates> element has a mode attribute, it applies only to those template rules from <xsl:template> elements that have a mode attribute with the same value; if an <xsl:apply-templates> element does not have a mode attribute, it applies only to those template rules from <xsl:template> elements that do not have a mode attribute.
Remarks
The <xsl:apply-templates> element first selects a set of nodes using the query specified in the select attribute. If this attribute is left unspecified, all children of the current node are selected. For each of the selected nodes, <xsl:apply-templates> directs the XSLT processor to find an appropriate <xsl:template> to apply. Templates are tested for applicability by comparing the node to the XPath expression specified in the template's match attribute. If more than one template satisfies the match pattern, the one appearing with the highest priority is chosen. If several templates have the same priority, the last in the style sheet is chosen.

For more information, see Handling Irregular Data Hierarchies.

Example
The following style sheet formats customer data in XML into an HTML <TABLE> element, where each row represents a customer and the columns represent the customer's name, address, and phone number. The <xsl:sort> element sorts the customers by state, with all customers from a single state sorted by name.

XML File (customers.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="applyt.xsl" ?>
<customers>
<customer>
<name>John Smith</name>
<address>123 Oak St.</address>
<state>WA</state>
<phone>(206) 123-4567</phone>
</customer>
<customer>
<name>Zack Zwyker</name>
<address>368 Elm St.</address>
<state>WA</state>
<phone>(206) 423-4537</phone>
</customer>
<customer>
<name>Albert Aikens</name>
<address>368 Elm St.</address>
<state>WA</state>
<phone>(206) 423-4537</phone>
</customer>
<customer>
<name>Albert Gandy</name>
<address>6984 4th St.</address>
<state>WA</state>
<phone>(206) 433-4547</phone>
</customer>
<customer>
<name>Peter Furst</name>
<address>456 Pine Av.</address>
<state>CA</state>
<phone>(209) 765-4321</phone>
</customer>
<customer>
<name>Dan Russell</name>
<address>9876 Main St.</address>
<state>PA</state>
<phone>(323) 321-7654</phone>
</customer>
</customers>
XSLT File (applyt.xsl)

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

<xsl:template match="/">
<HTML>
<BODY>
<TABLE border="1" cellspacing="0" cellpadding="2">
<xsl:apply-templates select="customers/customer">
<xsl:sort select="state"/>
<xsl:sort select="name"/>
</xsl:apply-templates>
</TABLE>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="customer">
<TR>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="address" />
<xsl:apply-templates select="state" />
<xsl:apply-templates select="phone" />
<xsl:apply-templates select="phone" mode="accountNumber"/>
</TR>
</xsl:template>

<xsl:template match="name">
<TD STYLE="font-size:14pt font-family:serif">
<xsl:apply-templates />
</TD>
</xsl:template>

<xsl:template match="address">
<TD> <xsl:apply-templates /> </TD>
</xsl:template>

<xsl:template match="state">
<TD> <xsl:apply-templates /> </TD>
</xsl:template>

<xsl:template match="phone">
<TD> <xsl:apply-templates /> </TD>
</xsl:template>

<xsl:template match="phone" mode="accountNumber">
<TD STYLE="font-style:italic">
1-<xsl:value-of select="."/>-001
</TD>
</xsl:template>

</xsl:stylesheet>
Formatted Output



Processor Output

<HTML>
<BODY>
<TABLE border="1" cellspacing="0" cellpadding="2">
<TR>
<TD STYLE="font-size:14pt font-family:serif">Peter Furst</TD>
<TD>456 Pine Av.</TD>
<TD>CA</TD>
<TD>(209) 765-4321</TD>
<TD STYLE="font-style:italic">
1-(209) 765-4321-001
</TD>
</TR>
<TR>
<TD STYLE="font-size:14pt font-family:serif">Dan Russell</TD>
<TD>9876 Main St.</TD>
...
</TR>
</TABLE>
</BODY>
</HTML>
cybernaute 2003-10-09
  • 打赏
  • 举报
回复
这是样板
有助于代码的重复利用和模块化
eg:
<xsl:template match="/">
...
<xsl:apply-templates select="doc/books/content"/>
...
</xsl:template> //template1

<!--*************************************-->
<xsl:template match="content">
...
</xsl:template> //template2

这样的话在template1中调用template2

kingdomzhf 2003-10-09
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_ref_overview_9yg5.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_ref_overview_9yg5.asp

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧