使用 bing api xslt
我正在尝试使用 Bing Image api,但无法使其正常工作。 我正在尝试转换结果,但转换不会返回任何有用的内容。 我认为这是因为我在命名空间上做了一些错误的事情,因为我发现它在所有 xml 相关语言中都非常令人困惑...
这是我从 Bing 收到的示例:
<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">
<Query>
<SearchTerms>natalie portman</SearchTerms>
</Query>
<mms:Image xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<mms:Total>644000</mms:Total>
<mms:Offset>0</mms:Offset>
<mms:Results>
<mms:ImageResult>
<mms:Title>Natalie Portman/natalie-portman-83</mms:Title>
<mms:MediaUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.jpg</mms:MediaUrl>
<mms:Url>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:Url><mms:DisplayUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:DisplayUrl>
<mms:Width>1024</mms:Width>
<mms:Height>768</mms:Height>
<mms:FileSize>95173</mms:FileSize>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Thumbnail>
<mms:Url>http://ts1.mm.bing.net/images/thumbnail.aspx?q=809383506038& amp;id=b829ae4c6df8866b6a07325bedca4bbd</mms:Url>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Width>160</mms:Width>
<mms:Height>120</mms:Height>
<mms:FileSize>3838</mms:FileSize>
</mms:Thumbnail></mms:ImageResult>
<mms:ImageResult>
... other ImageResults and closing tags.
这里是我当前的 xslt 转换:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<xsl:template match="/">
<list>
<xsl:for-each select="//mms:ImageResult" >
<element>
<image>
<url><xsl:value-of select="/mms:MediaUrl" /></url>
<width><xsl:value-of select="/mms:Width" /></width>
<height><xsl:value-of select="/mms:Height" /></height>
</image>
</element>
</xsl:for-each>
</list>
</xsl:template>
</xsl:stylesheet>
有人吗看到我的错误了吗? 因为这个转换返回给我:
<list xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<element>
<image>
<url/>
<width/>
<height/>
</image>
</element>
...
</list>
I'm trying to use the Bing Image api, but can't manage to get it working.
I'm trying to transform the result, but the transformation does not return anything useful.
I think this is because I'm doing something wrong with the namespaces, as it is something I find terribly confusing in all xml related languages...
here is an example of what I receive from Bing:
<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">
<Query>
<SearchTerms>natalie portman</SearchTerms>
</Query>
<mms:Image xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<mms:Total>644000</mms:Total>
<mms:Offset>0</mms:Offset>
<mms:Results>
<mms:ImageResult>
<mms:Title>Natalie Portman/natalie-portman-83</mms:Title>
<mms:MediaUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.jpg</mms:MediaUrl>
<mms:Url>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:Url><mms:DisplayUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:DisplayUrl>
<mms:Width>1024</mms:Width>
<mms:Height>768</mms:Height>
<mms:FileSize>95173</mms:FileSize>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Thumbnail>
<mms:Url>http://ts1.mm.bing.net/images/thumbnail.aspx?q=809383506038& amp;id=b829ae4c6df8866b6a07325bedca4bbd</mms:Url>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Width>160</mms:Width>
<mms:Height>120</mms:Height>
<mms:FileSize>3838</mms:FileSize>
</mms:Thumbnail></mms:ImageResult>
<mms:ImageResult>
... other ImageResults and closing tags.
here my curent xslt transformation:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<xsl:template match="/">
<list>
<xsl:for-each select="//mms:ImageResult" >
<element>
<image>
<url><xsl:value-of select="/mms:MediaUrl" /></url>
<width><xsl:value-of select="/mms:Width" /></width>
<height><xsl:value-of select="/mms:Height" /></height>
</image>
</element>
</xsl:for-each>
</list>
</xsl:template>
</xsl:stylesheet>
does somebody see my mistake(s)?
because this transform returns me:
<list xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<element>
<image>
<url/>
<width/>
<height/>
</image>
</element>
...
</list>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不应该是……
?
Shoudnt be...
?