Вопрос

I am new to xslt. Below is a xml fragment from a rdlc report. I would like to write a xsl transformation that tells me about cases where the "Field" attribute "Name" is not equal to the "DataField" child element. In the sample below that would be the last field (Name="Url").

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
    <DataSets>
        <DataSet Name="TestReportModel">              
            <Fields>
                <Field Name="Name">
                    <DataField>Name</DataField>
                    <rd:TypeName>System.String</rd:TypeName>
                </Field>
                <Field Name="Description">
                    <DataField>Description</DataField>
                    <rd:TypeName>System.String</rd:TypeName>
                </Field>
                <Field Name="Url">
                    <DataField>DataFieldDoesNotMatchAttribute</DataField>
                    <rd:TypeName>System.String</rd:TypeName>
                </Field>
            </Fields>
        </DataSet>
    </DataSets>
</Report>
Это было полезно?

Решение

Please try the stylesheet below:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:def="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"
    xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="def rd">

    <xsl:strip-space elements="*"/>

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

    <xsl:template match="/">
        <xsl:apply-templates select="def:Report/def:DataSets/def:DataSet/def:Fields/def:Field[@Name != def:DataField]"/>
    </xsl:template>

    <xsl:template match="def:Field">
        <Field>
            <xsl:copy-of select="@*"/>
            <DataField><xsl:value-of select="def:DataField"/></DataField>
            <xsl:copy-of select="rd:TypeName"/>
        </Field>
    </xsl:template>

</xsl:stylesheet>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top