如何在XSLT中获取属性名称



您能告诉我如何在XSLT中获取属性值吗?我有一个XML。我需要解析此XML。我想获得 blockQuote的类名称尝试过这样的尝试

XML

<amp_articleshow >
<article >
    <arttextnew>
        <page>
            <div class="section1">
                <div class="Normal">
                    Dipika Kakar and
                    <keyword keytype="UnKnown" smid="0" usetype="2" keywordseo="Shoaib-Ibrahim">Shoaib Ibrahim</keyword>
                    are currently seen showing off their dancing skills on
                    <keyword keytype="UnKnown" smid="0" usetype="2" keywordseo="Nach-Baliye-8">Nach Baliye 8</keyword>
                    and are one of the judges' favourite jodis.
                    <br/>
                    <br/>
                    Shoaib and Dipika are working really hard for their performances and have been giving their 100% to it.
                    <br/>
                    <br/>
                    Shoaib, who had earlier played the role of Prem on Sasural Simra Ka, crossed 100k followers on Instagram and the actor has been overwhelmed.
                    <br/>
                    <br/>
                    <strong>READ ALSO:</strong>
                    <br/>
                    <a class="inline-read" href="http://timesofindia.indiatimes.com/tv/news/hindi/nach-baliye-8-dipika-kakar-and-shoaib-ibrahims-hum-dil-de-chuke-moment/articleshow/58611440.cms">
                        <strong>
                            Nach Baliye 8: Dipika Kakar and Shoaib Ibrahim's 'Hum Dil De Chuke' moment
                        </strong>
                    </a>
                    <br/>
                    <br/>
                    He posted a video thanking his fans. He captioned it saying "#100K Followers! Can't believe I crossed this milestone. Thank you so much guys for all this love. Couldn't have done without you!😍😘🙌#LoveYouGuys #SoHappy"
                    <br/>
                    <br/>
                    <blockquote class="instagram-media" data-instgrm-captioned="" data-instgrm-version="7" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);">
                        <div style="padding:8px;">
                            <div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding:50.0% 0; text-align:center; width:100%;">
                                <div style=" background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAMUExURczMzPf399fX1+bm5mzY9AMAAADiSURBVDjLvZXbEsMgCES5/P8/t9FuRVCRmU73JWlzosgSIIZURCjo/ad+EQJJB4Hv8BFt+IDpQoCx1wjOSBFhh2XssxEIYn3ulI/6MNReE07UIWJEv8UEOWDS88LY97kqyTliJKKtuYBbruAyVh5wOHiXmpi5we58Ek028czwyuQdLKPG1Bkb4NnM+VeAnfHqn1k4+GPT6uGQcvu2h2OVuIf/gWUFyy8OWEpdyZSa3aVCqpVoVvzZZ2VTnn2wU8qzVjDDetO90GSy9mVLqtgYSy231MxrY6I2gGqjrTY0L8fxCxfCBbhWrsYYAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;"></div>
                            </div>
                            <p style=" margin:8px 0 0 0; padding:0 4px;">
                                <a href="https://www.instagram.com/p/BT_zxpgBIgO/" style=" color:#000; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none; word-wrap:break-word;" target="_blank">
                                    #100K Followers! Can't believe I crossed this milestone. Thank you so much guys for all this love. Couldn't have done without you!😍😘🙌#LoveYouGuys #SoHappy
                                </a>
                            </p>
                            <p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;">A post shared by shoaib Ibrahim (@shoaib2087) on</p>
                            <time datetime="2017-05-12T15:17:19+00:00" style=" font-family:Arial,sans-serif; font-size:14px; line-height:17px;">May 12, 2017 at 8:17am PDT</time>
                        </div>
                    </blockquote>
                    <br/>
                    <br/>
                    Shoaib is currently seen in 'Koi Laut Ke Aaya Hai' opposite Surbhi Jyotii, while Dipika was last seen on Colors' 'Sasural Simar Ka'.
                    <br/>
                    <br/>
                    This is the first time ever that they will appear together on a reality show. The duo have been dating each other for quite some time now and plan to tie the knot in January next year.
                </div>
            </div>
        </page>
    </arttextnew>

</article>
</amp_articleshow>

XSLT

<xsl:template match="amp_articleshow">
     <xsl:value-of select="//./article/descendant::blockquote[@class]"/>
    </xsl:template>

预期输出 :: Instagram-Media

这应该做技巧:

<xsl:template match="amp_articleshow">
   <xsl:value-of select="//./article/descendant::blockquote/@class"/>
</xsl:template>

这实际上是关于XPath的问题。

在XPATH /foo[@bar]中,选择一个具有属性bar的元素foo,但它不会给您bar的值,这是您想要的。


要获得属性的值,只需将查询更改为/foo/@bar,它确实为您提供了foo的值。

这是一个很好的链接,显示了节点选择的工作原理。

尝试:

<xsl:value-of select="//blockquote/@class"/>

请注意,在XSLT 1.0中,这将返回文档中 first blockQuote的类。

prepicates []将检查具有类属性的bolckquote是否意味着它将返回具有类属性的blockquote值。

blockquote[@class]

如果您想获得@class值,则应该像以下方式一样。

blockquote/@class

相关内容

  • 没有找到相关文章

最新更新