以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XSL/XSLT/XSL-FO/CSS 』 (http://bbs.xml.org.cn/list.asp?boardid=8) ---- 初学xsl的几个问题? (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=10730) |
-- 作者:fxbird -- 发布时间:10/1/2004 9:09:00 PM -- 初学xsl的几个问题? 且看如下的xml和xsl: xml: <Catalog> <Publisher isbn = "186100"> <!--出版社名--> <CorporateName>Wrox Press Ltd</CorporateName> <!--出版社的地址,可以有多个--> <Address headquarters = "yes"> <Street>Arden House</Street> <Street>1102 Warwick Road, Acocks Green</Street> <City>Birmingham</City> <Country>UK</Country> <PostalCode>B27 6BH</PostalCode> </Address> <Address headquarters = "no"> <Street>Suite 520</Street> <Street>29 S. Lasalle Street</Street> <City>Chicago</City> <PoliticalDivision>IL</PoliticalDivision> <Country>USA</Country> <PostalCode>60603</PostalCode> </Address> <!--出的书的类别--> <Imprints> <Imprint shortImprintName = "XML">XML and Scripting</Imprint> <Imprint shortImprintName ="Linux">GNU/Linux</Imprint> <Imprint shortImprintName ="Java">Java</Imprint> <Imprint shortImprintName ="ASP">Active Server Pages</Imprint> </Imprints> <!--签约作者--> <Author authorCiteID = "smohr"> <FirstName>Stephen</FirstName> <LastName>Mohr</LastName> <Biographical>Stephen Mohr is a senior systems architect...</Biographical> </Author> <Author authorCiteID = "nozu"> <FirstName>Nikola</FirstName> <LastName>Ozu</LastName> <Biographical>Nikola Ozu is a systems architect and consultant...</Biographical> </Author> <Author authorCiteID = "jond"> <FirstName>Jon</FirstName> <LastName>Duckett</LastName> <Biographical>The brains behind the Dr Evil organization, Jon is...</Biographical> </Author> <Author authorCiteID = "mbirbeck"> <FirstName>Mark</FirstName> <LastName>Birbeck</LastName> <Biographical>Mark Birbeck has been a professional programmer for...</Biographical> </Author> <Author authorCiteID = "mkay"> <FirstName>Michael</FirstName> <LastName>Kay</LastName> <Biographical>Michael Kay has spent most of ...</Biographical> </Author> <Author authorCiteID = "scottwoo"> <FirstName>Scott</FirstName> <LastName>Woodgate</LastName> <Biographical>Scott Woodgate, a Microsoft Certified Solution Developer, ...</Biographical> </Author> </Publisher> <!--书的线索--> <Thread threadID = "coreXML">Core XML</Thread> <Thread threadID ="proXML">Advanced Topics in XML</Thread> <Thread threadID ="msXML">Microsoft XML Products</Thread> <!--书--> <Book ISBN = "1861005059" level = "pro" pubdate = "06-01-2001" pageCount = "800" authors = "smohr mbirbeck nozu jond" threads = "coreXML proXML" imprint = "XML"> <Title>Professional XML, 2nd Edition</Title> <!--概要--> <Abstract>An update to the wildly successful first edition, Pro XML covers the full ...</Abstract> <!--章节--> <RecSubjCategories> <Category>Internet</Category> <Category>Internet Programming</Category> <Category>XML</Category> </RecSubjCategories> <Price currency = "USD">49.99</Price> </Book> <Book ISBN = "1861003129" level = "pro" pubdate = "07-2000" pageCount = "780" authors = "mkay" threads = "proXML" imprint = "XML"> <Title>XSLT Programmer's Reference</Title> <Abstract>The definitive guide to XSLT and XSLT programming ...</Abstract> <RecSubjCategories> <Category>Internet</Category> <Category>XML</Category> <Category>XSL</Category> </RecSubjCategories> <Price currency = "USD">34.99</Price> </Book> <Book ISBN = "1861003293" level = "pro" pubdate = "12-2000" pageCount = "700" authors = "smohr scottwoo" threads = "proXML msXML" imprint = "XML"> <Title>Professional BizTalk</Title> <Abstract>The first comprehensive guide to using and programming Microsoft BizTalk Server ...</Abstract> <RecSubjCategories> <Category>XML</Category> <Category>E-Commerce</Category> </RecSubjCategories> <Price currency = "USD">49.99</Price> </Book> </Catalog> 根元素由出版社(Publisher),书的线索(Thread),书(Book)组成。 在xsl求每本书的出版社名字的一段: <xsl:template match="Book"> <xsl:apply-templates select="Title"/> <xsl:variable name="isbn" select="@ISBN"/> <xsl:element name="DIV"> <xsl:attribute name="style">font-family:Verdana;font-size:10pt;color:black;font-weight:bolder</xsl:attribute> <xsl:value-of select="/Catalog/Publisher[contains($isbn,@isbn)]/CorporateName"/>//这个地方怎么有两个属性isbn,到底属于谁的,难道是模板匹配的当前属性ISBN(Book里的)优先考虑,@isbn匹配其指定的路径吗(Publisher里的)?属性名不同还好说,如果是同名的怎么办啊,如果是用到了三个这样的属性,又该如何匹配? </xsl:element> <xsl:variable name="by" select="@authors"/> <xsl:call-template name="fetch-authors"> <xsl:with-param name="authors" select="/Catalog/Publisher/Author[contains($by,@authorCiteID)]"/> </xsl:call-template> ....... 另外一个问题和xpath有关: <xsl:apply-templates select="*[name() != 'Title']"/> 这个模板从效果上看是匹配所有当前上下文节点的名字不为Title的子节点,可按照xpath的写法,我觉得前面应该加上child,才能表明是上子节点里去找,即:child::*[name()]!='Title',不知对不对,要不怎么知道到哪里去找呢?难道默认是到子节点里去找?我试了也可以,有点纳闷。 |
-- 作者:AlongleeNet -- 发布时间:10/2/2004 9:47:00 PM -- 是不是嫌我们的问题太简单了,没有人回答啊。 |
-- 作者:fxbird -- 发布时间:10/3/2004 10:07:00 AM -- 我还以为有回答了 |
-- 作者:AlongleeNet -- 发布时间:10/3/2004 10:51:00 AM -- 不好意思 我也是初学 对所有有关的问题我都感兴趣, 帮你顶 |
-- 作者:doubleG -- 发布时间:10/6/2004 9:11:00 AM -- <xsl:value-of select="/Catalog/Publisher[contains($isbn,@isbn)]/CorporateName"/>中的$isbn是指变量isbn-><xsl:variable name="isbn" select="@ISBN"/> @isbn是指属性。 <xsl:template match="Book"> <xsl:apply-templates select="Title"/> 这里的apply-templates是指在book下面的子节点来匹配这些模版的,所以就不用child了。 睡了几天头有些昏,回答的不好的话,请原谅。哈哈
|
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
93.750ms |