Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:29:40+00:00 2026-06-01T18:29:40+00:00

Using Visual Studio to perform the transform during development the resulting xml contains text

  • 0

Using Visual Studio to perform the transform during development the resulting xml contains text from the source xml in the destination that was contained in tags that do not match my template criteria

I was expecting that my select Group in the first template to find any elements named Group that are immediate children of CrystalReport and pass them along in the apply template call. I understood that the match filter on my second template would only take in Group‘s that have an attribute of Level=1 and write them out. I’d expect everything else to be ignored.

Why does “not this” appear in my output?

source

<?xml version="1.0" encoding="utf-8" ?>
<!--
 UPDATE: Note that adding the xmlns attribute causes all output
 to disappear unless you use Chris's second solution.
 -->
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" >
  <Group Level="1">
    <GroupHeader>
      <Section>
        <Field FieldName="apple" />
      </Section>
    </GroupHeader>
    <Group Level="2">
      not this
    </Group>
  </Group>
</CrystalReport>

transform

<?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" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/CrystalReport">
    <root>
        <xsl:apply-templates select="Group"/>
    </root>
  </xsl:template>

  <xsl:template match="Group[@Level='1']/GroupHeader">
    <tag1><xsl:value-of select="Section/Field/@FieldName"/></tag1>
  </xsl:template>
</xsl:stylesheet>

output

<?xml version="1.0" encoding="utf-8"?>
<root>
  <tag1>apple</tag1>
      not this
    </root>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:29:41+00:00Added an answer on June 1, 2026 at 6:29 pm

    You are facing the problem where the built in templates of the XML parser are coming into play. You are apply templates to all of the Group elements, but only catching one of them with your own templates. The other is handled by the default templates which out put the values of all nodes. I suggest that you change

     <xsl:template match="/CrystalReport">
    

    into

     <xsl:template match="/">
    

    This will override the root default templates which are producing the extra output. You can find more on the built in template rules at http://www.w3.org/TR/xslt#built-in-rule

    Then override the basic text() template so you final XSLT looks a bit like this

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <root>
            <xsl:apply-templates select="CrystalReport/Group"/>
        </root>
    </xsl:template>
    <xsl:template match="Group[@Level='1']/GroupHeader">
        <tag1>
            <xsl:value-of select="Section/Field/@FieldName"/>
        </tag1>
    </xsl:template>
    <xsl:template match="text()"/>
    

    UPDATE

    Or even simpler you could just match the desired elements and use something like this

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/CrystalReport">
        <root>
            <xsl:apply-templates select="Group[@Level='1']/GroupHeader"/>
        </root>
    </xsl:template>
    <xsl:template match="GroupHeader">
        <tag1>
            <xsl:value-of select="Section/Field/@FieldName"/>
        </tag1>
    </xsl:template>
    

    This will leave the default text() templates in place which can be very handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Profiler of Visual Studio 2008 Development Edition. To perform targeted profiling,
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
I have a Visual Studio 2010 solution that contains C# (managed), C++/CLI (unmanaged) and
I'm writing an application using Visual Studio C++ 2010 to perform Data Acquisition and
Is there a way to publish a web site from Visual Studio 2008 using
I am using Visual Studio 2010 Ultimate to perform loadtests. These loadtest use recorded
I am running a .NET 4.0 web application locally using the Visual Studio Development
I am using MSXML 6.0 to perform a transform of my own XML into
How can I perform web.config transformations using Visual Studio 2008? Someone had asked me
Using Visual Studio 2008 Team Edition, is it possible to assign a shortcut key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.