2013-10-25 67 views
0

我想在下面的格式来创建数据饲料中使用XSLT reformating,SSRS XML导出

<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> 

,但报表服务导出选项已产生以下XML数据文件不上谷歌商家中心工作。

<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>  

如果我连着上面提到的XSLT通过DataTransform属性的报告,我正在获得输出。

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

当你说“哪种类型的XSLT”是否指“哪个版本”?对于您的任务,XSLT 1.0应该可以正常工作,因为您只需要禁用一些标记并重命名其他标记。请首先咨询XSLT的一般指南(例如,从https://en.wikipedia.org/wiki/XSLT开始)。如果您遇到了具体的XSLT问题,您可以将其添加到上面的问题中,您将得到帮助。 –

+0

实际上我需要xslt代码来抑制标记 Details_Collection>并将标记

重命名为。如果您能为我提供xslt代码,我将不胜感激。谢谢! – user2538900

+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&amp;rs%3AFormat=XML&amp;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> 

注意事项:

  • 此XSLT只是将一个XML转换为另一个XML。在继续之前,您应该设置一个测试环境来检查这个方面。
  • 作为第二步,您应该进行修改(如果需要),将XSLT集成到您似乎拥有的自动处理设置中。我注意到字符串"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&amp;rs%3AFormat=XML&amp;rc%3ASchema=True"