?
Solved

Generic xslt needed to reproduce any xml file (doesn't have to be complicated)

Posted on 2004-11-25
3
Medium Priority
?
329 Views
Last Modified: 2008-02-26
Probably a simple one but anyone have any idea how I would produce an XSLT that would reproduce exactly any xml file?
0
Comment
Question by:madbastard09
  • 2
3 Comments
 
LVL 7

Expert Comment

by:J_Mak
ID: 12674113
If you have this simple XML file:

<?xml version="1.0"?>
<samples>
      <sample>Hello</sample>
      <sample>How are you</sample>
</samples>

And this is your XSLT stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="xml"/>
      <xsl:template match="/">
            <samples>
                  <xsl:apply-templates select="samples"/>
            </samples>
      </xsl:template>
      <xsl:template match="samples">
            <xsl:for-each select="sample">
                  <sample>
                        <xsl:value-of select="concat(.,' there')"/>
                  </sample>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>

This will be your resultant XML file:

<?xml version="1.0"?>
<samples>
      <sample>Hello there</sample>
      <sample>How are you there</sample>
</samples>

So I have simply changed the XML file to include an extra string 'there'. This is a very simple example and I hope it is understandable. If you have any questions, please don't hesitate to ask. Cheers.
0
 

Author Comment

by:madbastard09
ID: 12674189
Fine, but if i needed an xslt to tranform ANY into its indentical state then any specified variables such as 'sample' should not be needed. I currently have this:

  <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > 
          <xsl:output method = "xml"  />

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


     </xsl:stylesheet>


but it just produces the data and not the tags!
0
 
LVL 7

Accepted Solution

by:
J_Mak earned 2000 total points
ID: 12674493
Why don't you just copy the whole XML file like so:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="xml"/>
      <xsl:template match="/">
            <xsl:copy-of select="."/>
      </xsl:template>
</xsl:stylesheet>

Cheers.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question