以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  [求助]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=58551)


--  作者:JeffreyXu
--  发布时间:1/27/2008 11:19:00 AM

--  [求助]
那位能帮我解释一下这句语句的意思啊
<xsl:for-each select="following-sibling::CodeListing[ count(preceding-sibling::CodeTitle[1] | current()) = 1]">
--  作者:enyaxp
--  发布时间:1/27/2008 5:08:00 PM

--  
好诡异的表达式...

首先将表达式分解:
S1 = following-sibling::CodeListing[S2];
S2 = count(S3 | current()) = 1;
S3 = preceding-sibling::CodeTitle[1];

S1表示选择当前上下文节点的所有名为"CodeListing"并满足S2的兄弟元素;
S2是一种常用句式,count(x|y)=1,用于判断两节点是否相同;
  这里表示要求满足S3的节点和“当前”节点相同。
  注意,current()表示的“当前”节点是S1的当前上下文节点,而不是S2的上下文节点"CodeListing"!
S3表示当前CodeListing节点的前一个名为"CodeTitle"兄弟节点;

也就是说这个select要选中的是一个CodeListing节点,这个节点的前一个CodeTitle兄弟节点要和当前节点相同!

如果方便的话把对应的XML贴出来,不然现在还不确定这段代码要做什么.


--  作者:JeffreyXu
--  发布时间:1/27/2008 8:42:00 PM

--  
谢谢你解释
<xsl:apply-templates select="following-sibling::Para[ count(preceding-sibling::Title1[1] | current()) = 1]" />这句和前面那一句一样的,我也没理解,也是同一个xsl内的。因为XML太长,所以贴一部分出来,这部分是这一句需要解释的:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xslt_tools_full.xsl" ?>

<Word-Document>
 <ChapterTitle>
  <p>Finding and Using XSLT Tools</p>
 </ChapterTitle>
 <Para>
  <p>The XSLT transformation process always begins with a reading of an XML document, generally by a separate component called an XML parser or processor. The XML processor reads your input (see Chapter 1 for specifics on processing order) and verifies that the XSLT and XML documents are both well-formed. </p>
  <p>I've included a list of common XML processors because of the necessity of having one for XSLT. </p>
  <p>There are certain configurations of XML and XSLT processors that have become fairly standard within the industry. For example, the Xerces/Xalan combination probably has the most support for the J2EE platform (the Java platform for enterprise-level web sites), but it is hardly your only option. What makes it a nice combination is the simple fact that most J2EE application servers build their architecture around Xerces and Xalan, and therefore remove a ton of configuration chores from the developer. Java being what it is, you can always add your own XML parser/XSLT processor combination; it just requires some extra configuration time.</p>
  <p>Your choice of XSLT processors is going to be a subjective one based on a number of criteria. Heavy duty server-side transactions require caching mechanisms that generally fall outside the purvey of the XSLT processor, and are actually managed by other components in modern XSL Transformation systems. An example of this are the supporting classes for XML in Java, which have improved XSLT performance significantly over the last couple of years simply by introducing caching functions. The latest edition of MSXML does the same thing. MSXML and the JAVA API for XML consist of much more than an XML parser and XSLT processor, and feature a wide variety of performance-enhancing components that allow you to do everything from stream to HTTP to work with SAX (Simple API for XML) and DOM (The Document Object Model). </p>
  <p>At first glance there may appear to be a bias towards Microsoft's MSXML engine, but in truth most of the parsers and processors named in this appendix require little warning, and using them is pretty straightforward. They usually come with sufficient documentation, and have survived the test of time. The MSXML parser, on the other hand, is replete with versioning conflicts, and I've provided some tables to help you deal with them. Microsoft's early adoption of XML has had many good benefits, but it has come at a price for XSLT developers. </p>
  <p>The bottom line is that every application that appears in these pages is pretty good. The state of XML software development is very good these days, and competition is pretty fierce. Anything that appears in these pages is going to be reliable. And what about software that doesn't appear in these pages? That doesn't necessarily mean I tried it and didn't like it. The industry has so many good developers that there is a good chance I just missed it. Email me if you want your software listed in the next edition, or if you feel I missed something. Chance are, I have.</p>
 </Para>
 <Title1>
  <p>XML Parsers</p>
 </Title1>
 <Para>
  <p>The following is a list of XML Parsers. Installation of each depends on the environment, but I haven't encountered a parser that doesn't include easy-to-read instructions. Java programs require a Java Virtual Machine on your computer, and if you are on Windows many of them consist of installation routines that build your class paths for you. If you are on UNIX, Linux or Macintosh, you usually need to handle your class paths yourself. If you don't know Java at all, you might want to visit a tutorial site to at least learn the basics behind how it works, even if you don't want to learn how to program with it. Class path management is a bit of an art. Here is one tutorial you might want to look at:</p>

 </Para>
 <CodeSnippet_sp>
  <p>http://www.mike-levin.com/learning-java/toc.html</p>
 </CodeSnippet_sp>
 <RunInHead>
  <p>EXML (Eiffel) </p>
 </RunInHead>
 <RunInPara>
  <p>An XML 1.0 parser for Eiffel based on expat</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://exml.sourceforge.net/</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>expat - XML Parser Toolkit</p>
 </RunInHead>
 <RunInPara>
  <p>A non-validating XML 1.0 parser written in C.</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.jclark.com/xml/expat.html</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>fxp </p>
 </RunInHead>
 <RunInPara>
  <p>A validating XML parser written in the functional programming language SML.</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.informatik.uni-trier.de/~aberlea/Fxp/</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>HXML</p>
 </RunInHead>
 <RunInPara>
  <p>A non-validating parser for Haskell</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.flightlab.com/~joe/hxml</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>Java API for XML Parsing</p>
 </RunInHead>
 <RunInPara>
  <p>Sun's Java API for XML</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://java.sun.com/xml/index.html</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>Larval</p>
 </RunInHead>
 <RunInPara>
  <p>A validating XML processor built on the same code base as Lark, which is a non-validating XML processor implemented in the Java language</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.textuality.com/Lark/</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>Lotus Notes/Domino XML Toolkit</p>
 </RunInHead>
 <RunInPara>
  <p>Extends XML  support in Lotus Notes client and Domino Application Server, allowing content in a Domino database to be created and processed as native XML.</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.lotus.com/developers/devbase.nsf/homedata/homexmltk</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>LTXML</p>
 </RunInHead>
 <RunInPara>
  <p>LT XML is an integrated set of XML tools and a developers' tool-kit with a C-based API for UNIX and WIN32 ports.</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://www.ltg.ed.ac.uk/software/xml/</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>MSXML</p>
 </RunInHead>
 <RunInPara>
  <p>Microsoft's latest parser</p>
 </RunInPara>
 <CodeSnippetSub>
  <p>http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28000438</p>
 </CodeSnippetSub>
 <RunInHead>
  <p>SXP </p>
 </RunInHead>


--  作者:enyaxp
--  发布时间:1/27/2008 10:46:00 PM

--  
要匹配模版,匹配条件和上面的那句类似,所以就按上面的分析,最终找到节点如下:

<Title1>
  <p>XML Parsers</p>
</Title1>

如果没分析错的话你xsl里面应该有

  <xsl:template match="Title1">
     ......
  </xsl:template>
匹配的就是这个模版。


--  作者:Qr
--  发布时间:1/28/2008 12:11:00 PM

--  
XPath方面的知识,要多看看。
--  作者:JeffreyXu
--  发布时间:1/29/2008 8:48:00 PM

--  
没错!是有
<xsl:template match="Title1">
     ......
</xsl:template>
看了你的分析明了了许多,谢谢

--  作者:enyaxp
--  发布时间:1/30/2008 12:09:00 AM

--  
不客气,有什么问题再来问。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms