Cole Groff

Greenhorn
+ Follow
since Jun 24, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Cole Groff

Yeah, sorry if I did this wrong. I wasn't exactly sure how to phrase my question. Then I was able to solve to problem. I didn't want to leave this forum hanging, without concluding this somehow. I do appreciate the help, though.
Finally got a solution. This is used to add new XML to config files. If what is being added already exists, it is not added. The result is a new config file.

Hey Paul,

Sorry, I'm being a little unclear.

I'm making progress today, and when I'm finished for the day, I'll update the topic on what I've done and make things more clear.
Hey Paul,

My code has changed. This is the input file I'll be working with:
<configuration>
<configSections>
</configSections>
<appSettings>
</appSettings>
</configuration>

Here is the translation file code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>


<!-- creates new info to be added to the output -->
<xsl:variable name="source">

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

</xsl:variable>



<!-- merge input with "source" -->
<xsl:template match="configuration">
<configuration>
<xsl:copy-of select="*" />
<xsl:copy-of select="$source" />
</configuration>
</xsl:template>


</xsl:stylesheet>


There is a group of people who will be creating their own configuration tags. These are configurations for different aspects of the project. They will need to be able to hard code their configurations tags into the translation file. All of their configuration tags will need to be inserted inside the <configuration> tag, under the correct "second" tag.

Like in the translation code above, the tag <section .... /> will need to be added into a <configSections></configSections> tag, which is also under the root <configuration></configuration> tag.

Is there much I would need to change to my translation code to achieve this?
[ June 25, 2008: Message edited by: Cole Groff ]
I am very new to this. Right now my code looks like this:
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >

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

<!-- @* matches any attribute node -->
<!-- node() matches any node of any kind -->

<!-- copies all tags and their attributes under configuration -->
<xsl:template match = "node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>

<!-- maintains the short form tags -->
<xsl:template match="add[not(node())]|rar[not(node())]">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

This pretty much just copies an existing XML file to a new XML file. It also has a little bit of code to keep the short hand tags consistent (keeping them shorthand).

But... I ran into a book called the XSLT Cookbook. It has an example in it called "Merging Documents with Unlike Schema." I'm thinking this may be what I need.

Does anyone have experience with combining XML files?
[ June 25, 2008: Message edited by: Cole Groff ]
Here is an example of what I need to do:

Input XML file:
<configuration>
<appsettings>
<add key="111" value="222" />
<add key="111" value="222" />
</appsettings>
</configuration>

Then, I would need the output XML file to be something like this:
<configuration>
<appsettings>
<add key="111" value="222" />
<add key="111" value="222" />
</appsettings>
<other>
<add key="111" value="222" />
<add key="111" value="222" />
</other>
</configuration>

Does this make sense?

What I'm working on, is a master config file. I'm working on a project where a lot of people are working with different config files. I need to be able to have them use XSLT to transform their config file to match the master config file.
I am trying to modify XML config files using XSLT.

I have two goals at the moment:
1) To copy all tags and attributes from the config file, maintaining the hierarchy of the config file, to the new XML config file.
2) Being able to add new tags and attributes to the new XML config file.

Does anyone know how to do this? I've been trying the <xsl:element> element, but it isn't working so well. It has been overwriting config tags. How can I add new tags under the root tag?