Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 按位置替换文本?_Sql Server_Xml_Xslt_Reporting Services_Xquery - Fatal编程技术网

Sql server 按位置替换文本?

Sql server 按位置替换文本?,sql-server,xml,xslt,reporting-services,xquery,Sql Server,Xml,Xslt,Reporting Services,Xquery,我有以下XML文件(实际上是SQLServer报告服务RDL文件)。我想按位置将TablixCell中的替换为字段中的。即,“订单日期1”和“产品id 1”应分别替换为“订单日期”和“产品id” 最好可以在SQLServer2008中使用XQuery完成。如果没有,Xslt也可以 <Fields> <Field Name="order_date"> <DataField>order_date</DataField>

我有以下XML文件(实际上是SQLServer报告服务RDL文件)。我想按位置将
TablixCell
中的
替换为
字段中的
。即,“订单日期1”和“产品id 1”应分别替换为“订单日期”和“产品id”

最好可以在SQLServer2008中使用XQuery完成。如果没有,Xslt也可以

  <Fields>
    <Field Name="order_date">
      <DataField>order_date</DataField>
      <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="prod_id">
      <DataField>prod_id</DataField>
      <rd:TypeName>System.Int32</rd:TypeName>
    </Field>
    ....
  </Fields>
   ......
      <TablixRows>
            <TablixRow>
              <Height>0.25in</Height>
              <TablixCells>
                <TablixCell>
                     ......
                              <Value>order date1</Value>
                     ......
                </TablixCell>
                <TablixCell>
                     .....
                              <Value>prod id1</Value>
                     .....

订单日期
系统日期时间
产品标识
System.Int32
....
......
0.25英寸
......
订单日期1
......
.....
产品id1
.....
尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="TablixCell">
    <xsl:copy>
        <xsl:apply-templates>
            <xsl:with-param name="pos" select="position()"/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>

<xsl:template match="Value">
    <xsl:param name="pos"/>
    <xsl:copy>
        <xsl:value-of select="//Fields/Field[$pos]/DataField"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

当使用输入XML运行此命令时

<?xml version="1.0" encoding="UTF-8"?>
<Fields>
    <Field Name="order_date">
        <DataField>order_date</DataField>
        <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="prod_id">
        <DataField>prod_id</DataField>
        <rd:TypeName>System.Int32</rd:TypeName>
    </Field>
    <Field Name="xxx_id">
        <DataField>zzz_id</DataField>
        <rd:TypeName>System.String16</rd:TypeName>
    </Field>
    <TablixRows>
        <TablixRow>
            <Height>0.25in</Height>
            <TablixCells>
                <TablixCell>
                    <Value>order date1</Value>
                </TablixCell>
                <TablixCell>
                    <Value>prod id1</Value>
                </TablixCell>
                <TablixCell>
                    <Value>xxx id1</Value>
                </TablixCell>
            </TablixCells>
        </TablixRow>
    </TablixRows>
</Fields>

订单日期
系统日期时间
产品标识
System.Int32
zzz_id
System.16
0.25英寸
订单日期1
产品id1
xxx id1
结果是必需的

<?xml version="1.0" encoding="UTF-8"?>
<Fields>
    <Field Name="order_date">
        <DataField>order_date</DataField>
        <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="prod_id">
        <DataField>prod_id</DataField>
        <rd:TypeName>System.Int32</rd:TypeName>
    </Field>
    <Field Name="xxx_id">
        <DataField>zzz_id</DataField>
        <rd:TypeName>System.String16</rd:TypeName>
    </Field>
    <TablixRows>
        <TablixRow>
            <Height>0.25in</Height>
            <TablixCells>
                <TablixCell>
                    <Value>order_date</Value>
                </TablixCell>
                <TablixCell>
                    <Value>prod_id</Value>
                </TablixCell>
                <TablixCell>
                    <Value>zzz_id</Value>
                </TablixCell>
            </TablixCells>
        </TablixRow>
    </TablixRows>
</Fields>

订单日期
系统日期时间
产品标识
System.Int32
zzz_id
System.16
0.25英寸
订单日期
产品标识
zzz_id

您能详细解释一下您要完成的目标吗?我最初的想法是,您可以在rdl文件中查找和替换…但您尝试使用XQuery的事实让我想知道,是否还有比在这一个文件中替换字符串更大的目标。是的,如果一个XML文件中只有几个字段,则查找和替换工作正常。然而,50份报告中的每一份都有数百列,在提供的XML文件摘录中没有“prod_date”。摘录不是格式良好的XML文件,甚至不是格式良好的XML片段。请编辑并更正。SQL Server 2008是否支持XQUF(XQuery更新工具)扩展?如果是这样的话,使用XQuery的答案应该很简单。根据您要完成的任务,Reporting Services矩阵格式可以将数据透视以创建任意列。