首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从XML中进行选择--没有在XSLT中正确声明命名空间

无法从XML中进行选择--没有在XSLT中正确声明命名空间
EN

Stack Overflow用户
提问于 2013-08-14 19:44:29
回答 1查看 193关注 0票数 0

试图针对以下内容运行XSLT,但我认为名称空间有问题吗?

XML示例:

代码语言:javascript
复制
<rss version="2.0" xmlns="http://www.w3.org/ns/rex#" xmlns:mysmartprice="http://www.w3.org/2000/mysmartprice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<offers>
    <pubDate/>
    <title>ShopClues Deals Feed</title>
    <link>http://www.shopclues.com</link>
    <description>Great Deals on branded products</description>
    <language>en-gb</language>
    <offer>
        <mysmartprice:Product_Name>BreatheMaxTherapeuticPillow</mysmartprice:Product_Name>
        <mysmartprice:Price>4999.00</mysmartprice:Price>
        <mysmartprice:ourprice>4499.00</mysmartprice:ourprice>
        <mysmartprice:URL>http://www.shopclues.com/breathe-max-therapeutic-pillow.html</mysmartprice:URL>
        <mysmartprice:Prod_Image>http://cdn.shopclues.com/images/thumbnails/0/160/160/Breathe-Max-Therapeutic-P_1002001.000.CLM13218638854eca0acd18439.png</mysmartprice:Prod_Image>
        <mysmartprice:Shipping_Price>0</mysmartprice:Shipping_Price>
        <mysmartprice:Shipping_Time>5-7 working days</mysmartprice:Shipping_Time>
        <mysmartprice:Availability>Out Of Stock</mysmartprice:Availability>
        <mysmartprice:Brand>Calma</mysmartprice:Brand>
        <mysmartprice:Category>Bed Linen </mysmartprice:Category>
        <mysmartprice:SubCategory>Pillows</mysmartprice:SubCategory>
    </offer>
</offers>
</rss>

XSLT:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:omg="http://feeds.omgadmin.co.uk/feeds/ns/1.0/" xmlns:rss="http://feeds.omgeu.com/ns/1.0/" xmlns:mysmartprice="http://www.w3.org/2000/mysmartprice">
<xsl:param name="pubDate"/>
<xsl:param name="channelTitle" select="Test"/>
<xsl:param name="channelLink"/>
<xsl:param name="channelDescription"/>
<xsl:param name="channelLanguage"/>
<xsl:param name="channelCopyright"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/">
<rss version="2.0">
<channel>
    <pubDate><xsl:value-of select="$pubDate"/></pubDate>
    <title><xsl:value-of select="$channelTitle"/></title>
    <link><xsl:value-of select="$channelLink"/></link>
    <description><xsl:value-of select="$channelDescription"/></description>
    <language><xsl:value-of select="$channelLanguage"/></language>
    <copyright><xsl:value-of select="$channelCopyright"/></copyright>
    <omg:processCount><xsl:value-of select="count(//product)"/>    </omg:processCount>
    <xsl:apply-templates/>      
</channel>
</rss>
</xsl:template>
<xsl:template name="itemTemplate" match="offer">
    <item>
        <!--<omg:merchantrank>0</omg:merchantrank>-->
        <omg:pid>10543</omg:pid>
        <title><xsl:value-of select="mysmartprice:Product_Name"/></title>
        <description><xsl:value-of select="mysmartprice:Product_Name"/></description>
        <link><xsl:value-of select="mysmartprice:URL"/></link>
        <omg:imageurlsmall></omg:imageurlsmall>
        <omg:imageurlmedium><xsl:value-of select="mysmartprice:Prod_Image"/></omg:imageurlmedium>
        <omg:imageurllarge></omg:imageurllarge>
        <omg:price><xsl:value-of select="mysmartprice:ourprice"/></omg:price>
        <omg:currency>INR</omg:currency>    
        <omg:sku><xsl:value-of select="mysmartprice:Product_Name"/>-    <xsl:value-of select="mysmartprice:Brand"/></omg:sku>
    </item>
</xsl:template>
</xsl:stylesheet>

我已经在顶部做了命名空间声明,但是当我从XML中选择值时,我没有得到任何返回?

任何帮助都非常感谢。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-14 19:55:57

offer位于http://www.w3.org/ns/rex#命名空间中,因此您需要声明并使用它:

代码语言:javascript
复制
xmlns:rs="http://www.w3.org/ns/rex#"



<xsl:template name="itemTemplate" match="rs:offer">

顺便提一句,我不认为用http://www.w3.org/2000/mysmartprice将您自己的名称空间插入到http://www.w3.org/2000/mysmartprice中是非常合法的。您应该在您拥有的域中提出名称空间,或者使用类似于tempuri.net的名称作为域名。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18240880

复制
相关文章

相似问题

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