I'm trying to do an XSLT transformation that requires that I copy certain parts of the document multiple times and concatenate it to other individual parts. I'm working with xsl:copy and wildcards characters and coming up short on the output (I'm really trying to limit how many elements/attributes I have to reference directly as the actual schema is much larger than my example). Below is an example of the input then an example of the expected output I'm wanting. Can someone help get me started on accomplishing this? Thanks.

INPUT:

<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
	<ForAll>
		<GlobalID>123456</GlobalID>
		<OriginatingLoc>ABC</OriginatingLoc>
	</ForAll>
	<Order>
		<Customer>
			<Name>John Somebody</Name>
			<Gender>Male</Name>
			<DOB>1-1-1990</DOB>
		</Customer>
		<Address>
			<Street>1234 Lost Ave.</Street>
			<City>Someplace Nice</City>
			<State>TX</State>
		</Address>
	</Order>
	<Order>
		<Customer>
			<Name>Jane Else</Name>
			<Gender>Female</Name>
			<DOB>1-1-1984</DOB>
		</Customer>
		<Address>
			<Street>567 101st St</Street>
			<City>Lucky Town</City>
			<State>FL</State>
		</Address>
	</Order>
</TestXML>

EXPECTED OUTPUT:

<Output>
<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
<ForAll>
<GlobalID>123456</GlobalID>
<OriginatingLoc>ABC</OriginatingLoc>
</ForAll>
<Order>
<Customer>
<Name>John Somebody</Name>
<Gender>Male</Name>
<DOB>1-1-1990</DOB>
</Customer>
<Address>
<Street>1234 Lost Ave.</Street>
<City>Someplace Nice</City>
<State>TX</State>
</Address>
</Order>
</TestXML>
<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
<ForAll>
<GlobalID>123456</GlobalID>
<OriginatingLoc>ABC</OriginatingLoc>
</ForAll>
<Order>
<Customer>
<Name>Jane Else</Name>
<Gender>Female</Name>
<DOB>1-1-1984</DOB>
</Customer>
<Address>
<Street>567 101st St</Street>
<City>Lucky Town</City>
<State>FL</State>
</Address>
</Order>
</TestXML>
</Output>

Sorry my initial XML had some mismatched tags....here is the corrected XML.

Input:

<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
	<ForAll>
		<GlobalID>123456</GlobalID>
		<OriginatingLoc>ABC</OriginatingLoc>
	</ForAll>
	<Order>
		<Customer>
			<Name>John Somebody</Name>
			<Gender>Male</Gender>
			<DOB>1-1-1990</DOB>
		</Customer>
		<Address>
			<Street>1234 Lost Ave.</Street>
			<City>Someplace Nice</City>
			<State>TX</State>
		</Address>
	</Order>
	<Order>
		<Customer>
			<Name>Jane Else</Name>
			<Gender>Female</Gender>
			<DOB>1-1-1984</DOB>
		</Customer>
		<Address>
			<Street>567 101st St</Street>
			<City>Lucky Town</City>
			<State>FL</State>
		</Address>
	</Order>
</TestXML>

Output:

<Output>
	<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
		<ForAll>
			<GlobalID>123456</GlobalID>
			<OriginatingLoc>ABC</OriginatingLoc>
		</ForAll>
		<Order>
			<Customer>
				<Name>John Somebody</Name>
				<Gender>Male</Gender>
				<DOB>1-1-1990</DOB>
			</Customer>
			<Address>
				<Street>1234 Lost Ave.</Street>
				<City>Someplace Nice</City>
				<State>TX</State>
			</Address>
		</Order>
	</TestXML>
	<TestXML xmlns="http://something.com" xmlns:xsi="http://differentNS.com">
		<ForAll>
			<GlobalID>123456</GlobalID>
			<OriginatingLoc>ABC</OriginatingLoc>
		</ForAll>
		<Order>
			<Customer>
				<Name>Jane Else</Name>
				<Gender>Female</Gender>
				<DOB>1-1-1984</DOB>
			</Customer>
			<Address>
				<Street>567 101st St</Street>
				<City>Lucky Town</City>
				<State>FL</State>
			</Address>
		</Order>
	</TestXML>
</Output>

Could you explain the 2nd post as your "output" code is the same as input with the namespace declaration shown twice.

Which namespace (if any) are your nodes in? Im assuming none in which case will get back to you with the XSLT shortly.

My XSLT:

<xsl:stylesheet version="1.0"
  xmlns:x="http://something.com"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://differentNS.com"
  exclude-result-prefixes="xsi xsl" >

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

  <xsl:template match="text()">
    <xsl:apply-templates select="x:TestXML"/>
  </xsl:template>

  <xsl:template match ="x:TestXML">
    <xsl:variable name="GlobalID">
      <xsl:value-of select="x:ForAll/x:GlobalID"/>
    </xsl:variable>
    <xsl:variable name="OriginatingLoc">
      <xsl:value-of select="x:ForAll/x:OriginatingLoc"/>
    </xsl:variable>

    <xsl:for-each select="x:Order">
      <xsl:value-of select="$GlobalID"/>
      <xsl:value-of select="$OriginatingLoc"/>
      <xsl:value-of select="x:Customer/x:Name"/>
      <xsl:value-of select="x:Customer/x:Gender"/>
      <xsl:text>&#0010;</xsl:text>
      <xsl:value-of select="x:Customer/x:DOB"/>
      <xsl:text>&#0010;</xsl:text>
      <xsl:value-of select="x:Address/x:Street"/>
      <xsl:value-of select="x:Address/x:City"/>
      <xsl:value-of select="x:Address/x:State"/>
      <xsl:text>&#0010;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Produces the output you stated in the first post.

Hope it helps.

Edited 4 Years Ago by Mike Askew: Code Formatting Issue

This article has been dead for over six months. Start a new discussion instead.