亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 <xsl:template match=""> 來匹配作者

如何使用 <xsl:template match=""> 來匹配作者

大話西游666 2023-10-10 14:49:41
我正在嘗試使用 XML 和 XSL (XSLT) 生成 HTML 文件。我想展示某個作者(EX“Mario Vargas Llosa”)寫的所有書籍。如何使用 xsl:template 中的 match 屬性來做到這一點?XML代碼:<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href="template.xsl" type="text/xsl" ?><library>  <book>    <title language="es">La vida está en otra parte</title>    <author>Milan Kundera</author>    <publishDate year="1973"/>  </book>  <book>    <title language="es">Pantaleón y las visitadoras</title>    <author>Mario Vargas Llosa</author>    <publishDate year="1973"/>  </book>  <book>    <title language="es">Conversación en la catedral</title>    <author>Mario Vargas Llosa</author>    <publishDate year="1969"/>  </book>  <book>    <title language="en">Poems</title>    <author>Edgar Allan Poe</author>    <publishDate year="1890"/>  </book>    <book>    <title language="fr">Les Miserables</title>    <author>Victor Hugo</author>    <publishDate year="1862"/>  </book>    <book>    <title language="es">Plenilunio</title>    <author>Antonio Mu?oz Molina</author>    <publishDate year="1997"/>  </book>  </library>XSLT 代碼:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">    <html>    <head>        <link rel="stylesheet" href="style.css"/>    </head>        <body>            <xsl:for-each select="library/book">                <h1>Title:                     <xsl:value-of select="title"/>                </h1>                <p>                    <strong>Author: </strong>                    <xsl:value-of select="author"/>                </p>                <p>                    <strong>Publishing date: </strong>                    <xsl:value-of select="publishDate/@year"/>                </p>            </xsl:for-each>        </body>    </html></xsl:template>提前致謝。
查看完整描述

2 回答

?
縹緲止盈

TA貢獻2041條經驗 獲得超4個贊

將您的 XSLT 文件更改為


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

    <xsl:template match="/">

        <html>

        <head>

            <link rel="stylesheet" href="style.css"/>

        </head>

            <body>

                <xsl:for-each select="library/book[author='Mario Vargas Llosa']">

                    <h1>Title: 

                        <xsl:value-of select="title"/>

                    </h1>

                    <p>

                        <strong>Author: </strong>

                        <xsl:value-of select="author"/>

                    </p>

                    <p>

                        <strong>Publishing date: </strong>

                        <xsl:value-of select="publishDate/@year"/>

                    </p>

                </xsl:for-each>

            </body>

        </html>

    </xsl:template>

</xsl:stylesheet>

你的xsl:for-each意志會迭代<book>“馬里奧·巴爾加斯·略薩”的所有內容。所以輸出(在你的瀏覽器中)將是

https://img1.sycdn.imooc.com//6524f43f0001f46206290272.jpg

查看完整回答
反對 回復 2023-10-10
?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

XSLT 中的一行修改。您需要添加一個謂詞。

<xsl:for-each select="library/book[author='Mario Vargas Llosa']">


查看完整回答
反對 回復 2023-10-10
  • 2 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號