首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较xsl输出

比较xsl输出
EN

Stack Overflow用户
提问于 2016-06-27 11:10:11
回答 1查看 38关注 0票数 0

我有类似的xml文件

代码语言:javascript
复制
<section>
<dlentry xtrf="books.xml">
<dd>
<msgph>Harry Potter
</msgph>
</dd>
</dlentry>

<dlentry xtrf="books.xml">
<dd>
<msgph>1984
</msgph>
</dd>
</dlentry>

<dlentry xtrf="books.xml">
<dd>
<msgph>The Great Gatsby
</msgph>
</dt>
</dlentry>

<dlentry>
<dd>
<dl>
<dlentry xtrf="myFavouriteBooks.xml">
<dd>
<parml>
<plentry>
<pd>
<msgph>Harry Potter
</msgph>
</pd>    
</plentry>
</parml>
</dd>
</dlentry>
</dl>
</dd>        
</dlentry>

<dlentry xtrf="myBooks.xml">
<dd>
<msgph>1984
</msgph>
</dd>
</dlentry>

</section>

我需要做的是使用XSL创建2个列表,首先使用具有id!="books.xml"的"dlentry“元素的值,然后使用id="books.xml".。然后,我应该比较这些列表,并与所有不匹配的元素一起给出注意信息。

就像“注意!!失踪!1984!失踪!The Great Gatsby__”

现在我有了xsl:

代码语言:javascript
复制
<xsl:variable name="inBooks" select="/dlentry/dd/msgph"/>    
<xsl:variable name="notInBooks" select="//dlentry[not(contains(@xtrf,'books.xml))]//msgph/node()[not(self::dlentry)])" as="item()*"/>

<title>Books</title>

<refbody>  
   <section>
      <dl>                              
         <dlentry>                   
         <xsl:variable name="notMatched" select="//dlentry[not(contains(@xtrf,'books.xml'))]//msgph[msgph !='$inBooks']/node()[not(self::dlentry)])"/>

            <xsl:choose>
               <xsl:when test="$notMatched">
                  <xsl:for-each select="section/dl/dlentry">
                     <dt>
                        <xsl:value-of select="concat('!MISSING! ', msgph")/>
                     </dt>
                  </xsl:for-each>
               </xsl:when>
               <xsl:otherwise>
                <xsl:for-each select="section/dl/dlentry">
                    <dt>
                       <xsl:value-of select="msgph"/>
                    </dt>
                </xsl:for-each>

               </xsl:otherwise>
          </xsl:choose> 

        <dt>                               
           <xsl:value-of select="$notInBooks"/> 
        </dt>
<../>           

它给出了输出:

代码语言:javascript
复制
<title>Books</title>

<refbody>
  <section>
     <dl>
        <dlentry>

           <dt>The Great Gatsby</dt>
           <dt>1984</dt>
           <dt>Harry Potter Part 2</dt>
           <dt>Harry Potter Part 1</dt>
           <dd/>
           <dt>Harry Potter Part 1 Harry Potter Part 2</dt>
        </..>

我试过几百种组合,但不起作用。现在它应该加上“!失踪!”一个列表"id=books",但它只给了一个空的元素,你能指出我,请问我的错误在哪里?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-27 12:53:32

我假设您至少可以使用XSLT2.0,然后您可以使用

代码语言:javascript
复制
<xsl:variable name="b1" select="//dlentry[contains(@xtrf, 'books.xml')]"/>
<xsl:variable name="b2" select="//dlentry[not(contains(@xtrf, 'books.xml'))]"/>

<xsl:variable name="b3" select="$b1[not(.//msgph/normalize-space() = $b2//msgph/normalize-space())]"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38052432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档