目标:将CRM动态的odata xml文件导入SSIS转换块。
SSIS违禁品:
简化xml源
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="https://XXXXXXXXXX/XRMServices/2011/OrganizationData.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">allianceSet</title>
<entry>
<link rel="edit" title="be_alliance" href="be_allianceSet(guid'429352cb-deca-e311-80c0-00155d5682af')" />
<link rel="XXXX" type="application/atom+xml;type=entry" title="lk_be_alliance_createdby" href="be_allianceSet/lk_be_alliance_createdby" />
<link rel="XXXX" type="application/atom+xml;type=entry" title="lk_be_alliance_createdonbehalfby" href="be_allianceSet(/lk_be_alliance_createdonbehalfby" />
<content type="application/xml">
<m:properties>
<d:ModifiedOn m:type="Edm.DateTime">2015-10-30T13:06:31Z</d:ModifiedOn>
<d:CreatedBy m:type="Microsoft.Crm.Sdk.Data.Services.EntityReference" m:null="true">
<d:Id m:type="Edm.Guid">40f20074-ede3-48cc-aafc-750a1275b99b</d:Id>
<d:LogicalName>systemuser</d:LogicalName>
</d:CreatedBy>
<d:statecode m:type="Microsoft.Crm.Sdk.Data.Services.OptionSetValue">
<d:Value m:type="Edm.Int32">0</d:Value>
</d:statecode>
</m:properties>
</content>
</entry>
</feed>
XSL输入1.0
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="*[name() != 'link']">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<!-- template to copy attributes -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
上面的xsl完全删除了名称空间。但是,我试图用一个guid值来转换/扁平type="Microsoft.Crm.Sdk.Data.Services.EntityReference“的每个节点
...
<CreatedBy type="Microsoft.Crm.Sdk.Data.Services.EntityReference" null="true">
<Id type="Edm.Guid">40f20074-ede3-48cc-aafc-750a1275b99b</Id>
<LogicalName>systemuser</LogicalName>
</CreatedBy>
...
转到
...
<CreatedBy>40f20074-ede3-48cc-aafc-750a1275b99b</CreatedBy>
...
到目前为止没有任何运气..。感谢你的任何帮助
发布于 2016-03-16 09:39:30
看起来,您正在避免引用XSLT中的任何特定名称空间。如果是这样的话,要匹配具有"Microsoft.Crm.Sdk.Data.Services.EntityReference",类型属性的节点,就需要一个模板匹配,如下所示:
<xsl:template match="*[@*[local-name() = 'type']='Microsoft.Crm.Sdk.Data.Services.EntityReference']">
试试这个XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="*[local-name() = 'link']" />
<xsl:template match="*[@*[local-name() = 'type']='Microsoft.Crm.Sdk.Data.Services.EntityReference']">
<xsl:element name="{local-name()}">
<xsl:value-of select="*[local-name() = 'Id']" />
</xsl:element>
</xsl:template>
<!-- template to copy attributes -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
注意我是如何创建一个单独的模板来删除link
元素的。使用当前的XSLT,链接元素实际上将与XSLT的内置模板相匹配,如果存在任何文本节点,该模板将输出link
下的任何文本节点(这对您可能不是这样,但可能更好地为其编写代码)。
当然,如果您一直在处理具有相同名称空间的XML文档,您可以在XSLT中引用这些文档,如下所示:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="atom:link" />
<xsl:template match="*[@m:type='Microsoft.Crm.Sdk.Data.Services.EntityReference']">
<xsl:element name="{local-name()}">
<xsl:value-of select="d:Id" />
</xsl:element>
</xsl:template>
<!-- template to copy attributes -->
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
https://stackoverflow.com/questions/36039627
复制