• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

Using stx:copy

Hey experts,

 I want to use stx right now to copy an xml file as is (later I might remove some nodes), so I am using the following stx code:

<stx:transform       xmlns:stx="http://stx.sourceforge.net/2002/ns"
                xmlns:eteb="http://www.etis.org/EBG/ETEB"
                version="1.0">

  <stx:template match="ediroot">
        <stx:copy attributes="@*">
           <stx:process-children group="COPYALL" />
      </stx:copy>
  </stx:template>
 
  <stx:group name="COPYALL">
    <stx:template match="*">
        <stx:copy attributes="@*">
            <stx:value-of select="."/>
                  <stx:process-children group="COPYALL"/>
            </stx:copy>
    </stx:template>
  </stx:group>

</stx:transform>

Apparently, the code above is not working (it's adding weird nodes that sum the text of two nodes)...any help on the correct syntax to generate a target xml file identical to the source??
0
mte01
Asked:
mte01
  • 4
  • 2
  • 2
2 Solutions
 
Geert BormansInformation ArchitectCommented:
Hey,
I suspect you need something like this

<stx:group name="COPYALL">
    <stx:template match="*">
        <stx:copy>
            <stx:copy-of "@*" />
            <stx:value-of select="."/>
               <stx:process-children group="COPYALL"/>
          </stx:copy>
    </stx:template>
  </stx:group>
0
 
mte01Author Commented:
>>Gertone

Thanks for your reply, are you sure of the syntax of stx:copy-of (it's giving me a syntax error).....
0
 
Geert BormansInformation ArchitectCommented:
mte01,
> are you sure of the syntax of stx:copy-of (it's giving me a syntax error)....

you are right, the original was correct, (mixed up with XSLT syntax, sorry)
I will dig deeper, hang on
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
jkmyoungCommented:
Your problem may be with
<stx:value-of select="."/>
<stx:process-children group="COPYALL"/>

Here you handle all the text first, (thus grouping together text nodes)
then deal with the childeren group which only deals with elements

I'm not an expert with stx, but suggest you have something like this where you add an extra template for the text nodes, and remove the text handling inside the element template:

 <stx:group name="COPYALL">
    <stx:template match="*">
        <stx:copy attributes="@*">
               <stx:process-children group="COPYALL"/>
          </stx:copy>
    </stx:template>

    <stx:template match="text()">
    </stx:template>
  </stx:group>

Hope this solves your problem
0
 
Geert BormansInformation ArchitectCommented:

Do you get duplicates of text?
The <stx:value-of select="."/> looks suspicious to me.
I would expect this to be covered by process-children

maybe you need to have an explicit entry for text nodes in the match of the statement
   <stx:template match="* | text()">
        <stx:copy>
            <stx:copy-of "@*" />
               <stx:process-children group="COPYALL"/>
          </stx:copy>
    </stx:template>

let's see what this brings
0
 
jkmyoungCommented:
oops, forgot to repaste <stx:value-of> inside the text() template.

<stx:group name="COPYALL">
    <stx:template match="*">
        <stx:copy attributes="@*">
               <stx:process-children group="COPYALL"/>
        </stx:copy>
    </stx:template>

   <stx:template match="text()">
      <stx:value-of select="."/>
   </stx:template>
</stx:group>
0
 
Geert BormansInformation ArchitectCommented:
you might also set the the pass-through attribute to text


<stx:transform      xmlns:stx="http://stx.sourceforge.net/2002/ns"
               pass-through = "text"
                xmlns:eteb="http://www.etis.org/EBG/ETEB"
                version="1.0">
0
 
mte01Author Commented:
>>Gertone, jkmyoung

Apparently...this was the correct way, after further investigation:

<stx:group name="COPYALL">
    <stx:template match="*">
        <stx:copy attributes="@*">
            <stx:value-of select="."/>
               <stx:process-children group="COPYALL"/>
          </stx:copy>
              <stx:process-siblings group="COPYALL" />
    </stx:template>
  </stx:group>

Many thanks for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now