xsl-list
[Top] [All Lists]

[xsl] Issue with copying an element

2006-12-20 11:28:10
Hi All, 

I am new to xsl programming. I am trying to copy an element and 
paste it in the same level as the copied element. I am using some condition 
to check for an element value to decide whether to copy of or not. I am using 2 
xml files and a xsl. I have attached the xml and xsl files. In 
contentA-format2.xml, I am checking for "zh_CN" value under 
packageBody/importCon=
tentInstance/contentInstance/relation/attribute(_at_)language/valueString, if 
"zh_CN" is not present, then I need to copy the entire <relation> node and 
paste it under packageBody/importContentInstance/contentInstance/. And also I 
need to apply the   
<xsl:template 
match=3D"relation[(_at_)name=3D'CONTENT-MANAGEMENT-CT-LITERATURE-TRANS']/*"> 
again for the copied element.=0A=0AWhen I apply the xsl, the <relation> element 
is getting copied inside the original =
<relation> itself. 

contentA-format2.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<packageBody>
 <importWorkflow>
 </importWorkflow>
 <importContentType>
 </importContentType>
 <importContentType>
 </importContentType>
 <importContentInstance>
  <group name="VGNGRP_1" />
  <contentInstance
   vcmId="b3489d5648b9f010VgnVCM10000081141eacRCRD"
   vcmLogicalPath="/www/Literature/FPD" vcmName="Testing - FPD 32">
   <contentTypeId>
    0d82968ac17b8010VgnVCM1000005e191eac____
   </contentTypeId>
   <attribute name="literature-id">
    <valueString>
     a3489d5648b9f010VgnVCM10000081141eac____
    </valueString>
   </attribute>
   <attribute name="name">
    <valueString>Testing - FPD 32</valueString>
   </attribute>
   <attribute name="brand">
    <valueString></valueString>
   </attribute>
   <attribute name="type">
    <valueString>SPECF</valueString>
   </attribute>
   <attribute name="format">
    <valueString></valueString>
   </attribute>
   <attribute name="thumbnail">
    <valueString></valueString>
   </attribute>
   <attribute name="revision-date">
    <valueDate></valueDate>
   </attribute>
   <attribute name="owner">
    <valueString></valueString>
   </attribute>
   <relation name="CONTE
e name="CT-LITERATURE-TRANS-LITERATUREID">
     <valueString>
      a3489d5648b9f010VgnVCM10000081141eac____
     </valueString>
    </attribute>
    <attribute name="trans-id">
     <valueInt>81</valueInt>
    </attribute>
    <attribute name="title">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="description">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="language">
     <valueString>en_US</valueString>
    </attribute>
    <attribute name="file">
     <valueString></valueString>
    </attribute>
    <attribute name="partnumber">
     <valueString></valueString>
    </attribute>
   </relation>
   <acl>
    <entry name="vgnadmin" type="user">
     <grants>
      <capability application="VCM"
       name="MODIFY_TAX_ASSOCS" />
      <capability application="VCM" name="MODIFY" />
      <capability application="VCM" name="MODIFY_ACL" />
      <capability application="VCM" name="DELETE" />
      <capability application="VCM"
       name="PROMOTE_AND_DEMOTE" />
      <capability application="VCM"
       name="SECURITY_READ" />
      <capability application="VCM"
       name="DEPLOY_AND_UNDEPLOY" />
      <capability application="VCM"
       name="FLSLITERATURECT_READ" />
      <capability application="VCM"
       name="SECURITY_WRITE" />
      <capability application="VCM"
       name="FLSLITERATURECT_WRITE" />
      <capability application="VCM"
       name="WORKFLOW_DEF_READ" />
      <capability application="VCM"
       name="FLSLITERATURECT_DELETE" />
     </grants>
    </entry>
   </acl>
  </contentInstance>
 </importContentInstance>
</packageBody>

contentA-Translated.xml:-

<?xml version="1.0" encoding="UTF-8"?>
<packageBody xmlns="http://www.vignette.com/xmlschemas/importexport";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 xsi:schemaLocation="http://www.vignette.com/xmlschemas/importexport 
7202/packageBody.xsd">
 <contentInstance vcmID="b3489d5648b9f010VgnVCM10000081141eacRCRD">
  <contentid>a3489d5648b9f010VgnVCM1000008
sh</title>
  <teaser />
  <body />
  <description>FPD32 - English 111</description>
  <keywords />
  <language>en_US</language>
 </contentInstance>
 <contentInstance vcmID="b3489d5648b9f010VgnVCM10000081141eacRCRD">
  <contentid>a3489d5648b9f010VgnVCM10000081141eac____</contentid>
  <transid>81</transid>
  <title>FPD32 - CHINESE</title>
  <teaser />
  <body />
  <description>FPD32 - CHINESE</description>
  <keywords />
  <language>zh_CN</language>
 </contentInstance>
</packageBody>

merge.xslt:-
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:exsl="http://exslt.org/common"; 
  xmlns:vign="http://www.vignette.com/xmlschemas/importexport";>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
  <xsl:param name="xml2" />
  <xsl:template match="/">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:template>
  <xsl:template 
match="relation[(_at_)name='CONTENT-MANAGEMENT-CT-LITERATURE-TRANS']/*">
  <xsl:variable name="tagName">
      <xsl:value-of select="@name"/>
  </xsl:variable>
     <xsl:variable name="contentId" 
select="../attribute[(_at_)name='CT-LITERATURE-TRANS-LITERATUREID']/valueString/text()"/>
     <xsl:variable name="language" 
select="../attribute[(_at_)name='language']/valueString/text()"/>
      <xsl:choose>
       <xsl:when 
test="exsl:node-set($xml2)/packageBody/contentInstance[contentid=$contentId and 
language=$language]/*[local-name()=$tagName]">
         <xsl:copy-of 
select="exsl:node-set($xml2)/packageBody/contentInstance[contentid=$contentId 
and language=$language]/*[local-name()=$tagName]"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:copy-of select="."/>
       </xsl:otherwise>
     </xsl:choose>
  </xsl:template>
  <xsl:template 
match="//relation[(_at_)name='CONTENT-MANAGEMENT-CT-LITERATURE-TRANS']/attribute[(_at_)name='language']">
      <xsl:choose>
         <xsl:when test="/valueString/text() = 'zh_CN'">
         </xsl:when>
         <xsl:otherwise>
      <xsl:for-each 
select="//relation[(_at_)name='CONTENT-MANAGEMENT-CT-LITERATURE-TRANS']/a
uage']">
    <xsl:if test="valueString[.='en_US']">
     <xsl:copy-of select=".."/>
     <xsl:copy>
           <xsl:copy-of select="."/>
     </xsl:copy>
    </xsl:if>
      </xsl:for-each>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Output should look like :-

<?xml version="1.0" encoding="UTF-8"?>
<packageBody>
 <importWorkflow></importWorkflow>
 <importContentType>
 </importContentType>
 <importContentType>
 </importContentType>
 <importContentInstance>
  <group name="VGNGRP_1" />
  <contentInstance
   vcmId="b3489d5648b9f010VgnVCM10000081141eacRCRD"
   vcmLogicalPath="/www/Literature/FPD" vcmName="Testing - FPD 32">
   <contentTypeId>
    0d82968ac17b8010VgnVCM1000005e191eac____
   </contentTypeId>
   <attribute name="literature-id">
    <valueString>
     a3489d5648b9f010VgnVCM10000081141eac____
    </valueString>
   </attribute>
   <attribute name="name">
    <valueString>Testing - FPD 32</valueString>
   </attribute>
   <attribute name="brand">
    <valueString />
   </attribute>
   <attribute name="type">
    <valueString>SPECF</valueString>
   </attribute>
   <attribute name="format">
    <valueString />
   </attribute>
   <attribute name="thumbnail">
    <valueString />
   </attribute>
   <attribute name="revision-date">
    <valueDate />
   </attribute>
   <attribute name="owner">
    <valueString />
   </attribute>
   <relation name="CONTENT-MANAGEMENT-CT-LITERATURE-TRANS">
    <attribute name="CT-LITERATURE-TRANS-LITERATUREID">
     <valueString>
      a3489d5648b9f010VgnVCM10000081141eac____
     </valueString>
    </attribute>
    <attribute name="trans-id">
     <valueInt>81</valueInt>
    </attribute>
    <attribute name="title">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="description">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="language">
     
ute name="file">
     <valueString />
    </attribute>
    <attribute name="partnumber">
     <valueString />
    </attribute>
   </relation>
   <relation name="CONTENT-MANAGEMENT-CT-LITERATURE-TRANS">
    <attribute name="CT-LITERATURE-TRANS-LITERATUREID">
     <valueString>
      a3489d5648b9f010VgnVCM10000081141eac____
     </valueString>
    </attribute>
    <attribute name="trans-id">
     <valueInt>81</valueInt>
    </attribute>
    <attribute name="title">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="description">
     <valueString>FPD32 - English</valueString>
    </attribute>
    <attribute name="language">
     <valueString>en_US</valueString>
    </attribute>
    <attribute name="file">
     <valueString />
    </attribute>
    <attribute name="partnumber">
     <valueString />
    </attribute>
   </relation>
   <acl>
    <entry name="vgnadmin" type="user">
     <grants>
      <capability application="VCM"
       name="MODIFY_TAX_ASSOCS" />
      <capability application="VCM" name="MODIFY" />
      <capability application="VCM" name="MODIFY_ACL" />
      <capability application="VCM" name="DELETE" />
      <capability application="VCM"
       name="PROMOTE_AND_DEMOTE" />
      <capability application="VCM"
       name="SECURITY_READ" />
      <capability application="VCM"
       name="DEPLOY_AND_UNDEPLOY" />
      <capability application="VCM"
       name="FLSLITERATURECT_READ" />
      <capability application="VCM"
       name="SECURITY_WRITE" />
      <capability application="VCM"
       name="FLSLITERATURECT_WRITE" />
      <capability application="VCM"
       name="WORKFLOW_DEF_READ" />
      <capability application="VCM"
       name="FLSLITERATURECT_DELETE" />
     </grants>
    </entry>
   </acl>
  </contentInstance>
 </importContentInstance>
</packageBody>


I appreciate if you can help me how to resolve this issue.
Thanks
Chandar

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection ar

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Issue with copying an element, Microthunder <=