我正在尝试以下列格式创建数据Feed
<rss version="2.0">
<channel>
<Title>FeedTitle</Title>
<link>http://www.mydomain.com</link>
<description>My Products</description>
<item>
<Id>10890</Id>
<Title>Benetton 01</Title>
</item>
<item>
<Id>10700</Id>
<Title>Benetton 02</Title>
</item>
</channel>
</rss>
但是,Reporting Services导出选项已生成以下xml数据Feed,该数据Feed无法在Google Merchant Center上使用。
<Report xsi:schemaLocation="pg_google_data_feed http://reportserver?%2Fpg_google_data_feed&rs%3AFormat=XML&rc%3ASchema=True" Name="pg_google_data_feed">
<Title>FeedTitle</Title>
<link>http://www.mydomain.com</link>
<description>My Products</description>
<ProductList>
<Details_Collection>
<Details>
<Id>10890</Id>
<Title>Benetton 01</Title>
</Details>
<Details>
<Id>10700</Id>
<Title>Benetton 02</Title>
</Details>
</Details_Collection>
</ProductList>
</Report>
如果任何正文告诉我将XML数据重新格式化为另一个xml文件需要什么类型的XSLT,那将非常有用。
编辑:
步骤1.使用以下代码创建xslt文件。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="Details">
<Details>
<xsl:for-each select="@*">
<xsl:element name="{name(.)}">
<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</Details>
</xsl:template>
</xsl:stylesheet>
步骤2:将报告属性设置为“datafeed.xslt”
如果不将xslt应用于我的ssrs,报告结果将显示如下,
<Report xsi:schemaLocation="pg_google_data_feed http://reportserver?%2Fpg_google_data_feed&rs%3AFormat=XML&rc%3ASchema=True" Name="pg_google_data_feed">
<Title>FeedTitle</Title>
<link>http://www.mydomain.com</link>
<description>My Products</description>
<ProductList>
<Details_Collection>
<Details>
<Id>1000</Id>
</Details>
<Details>
<Id>1000</Id>
</Details>
</Details_Collection>
</ProductList>
</Report>
如果我通过DataTransform属性将上面提到的xslt附加到报告中,我会得到以下输出。
XML Parsing Error: syntax error
Location: file:///C:/Documents%20and%20Settings/Administrator/Desktop/pg_google_data_feed.xml
Line Number 1, Column 39:<?xml version="1.0" encoding="utf-8"?>1089010947109191093310895108921092406598115141151311512
--------------------------------------^
提前谢谢你 Sudhakar
答案 0 :(得分:2)
在输入周围略微更新包装
<?xml version="1.0" encoding="ISO-8859-1"?>
<Report
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="pg_google_data_feed http://reportserver?%2Fpg_google_data_feed&rs%3AFormat=XML&rc%3ASchema=True" Name="pg_google_data_feed">
<!-- everything else stays the same here -->
</Report>
以下XSLT将提供所需的转换和过滤
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="xsi">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<!-- rule to suppress the undesired nodes -->
<xsl:template match="Report|ProductList|Details_Collection">
<xsl:apply-templates/>
</xsl:template>
<!-- rule to rename the Details node -->
<xsl:template match="Details">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
<!-- rule to copy everything else -->
<!-- see http://stackoverflow.com/questions/857010/xsl-avoid-exporting-namespace-defintions-to-resulting-xml-documents-->
<!-- see http://stackoverflow.com/questions/14166259/xslt-default-template-confusion -->
<xsl:template match="*|@*">
<xsl:element name="{name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- rule to start the conversion and provide the wrapper tags -->
<xsl:template match="/">
<rss version="2.0">
<channel>
<xsl:apply-templates/>
</channel>
</rss>
</xsl:template>
</xsl:stylesheet>
注意:
"pg_google_data_feed http://reportserver?%2Fpg_google_data_feed&rs%3AFormat=XML&rc%3ASchema=True"
似乎没有效果,因为它包含未加引号的&符号。您可能希望改为使用"pg_google_data_feed http://reportserver?%2Fpg_google_data_feed&rs%3AFormat=XML&rc%3ASchema=True"
。