473,789 Members | 3,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing dummy attribute with string of xml

7 New Member
Very new to XML/XSL, so please forgive me if this is an incredibly simple question. I've been pulling my hair out over this for several days now.

I'm working on an internal application that takes the output from a custom Excel spreadsheet, and creates a Final Cut Pro sequence in XML. Due to the way Excel handles nested repeating elements, I need to find a way to replace a dummy element I have created with a whole series of repeating elements. I could use a simple find and replace text editor method, but I would prefer to take care of everything in the xslt transform if possible. Any ideas?

Thanks!


My existing XSL (which just strips out the empty tags) is posted at the bottom.

The code is as follows.

Expand|Select|Wrap|Line Numbers
  1. <effect>
  2.     <name>Text</name>
  3.     <effectid>Text</effectid>
  4.     <effectcategory>Text</effectcategory>
  5.     <effecttype>generator</effecttype>
  6.     <mediatype>video</mediatype>
  7.     <parameter>
  8.               <parameterid>str</parameterid>
  9.           <name>Text</name>
  10.           <value>Tuesday at 10:00</value>
  11.     </parameter>
  12.     <dummyattr>replace_me</dummyattr>
  13. </effect>
  14.  
I need to replace <dummyattr>repl ace_me</dummyattr>
with the following (these are not variables, elements and data will always be the same):


Expand|Select|Wrap|Line Numbers
  1. <parameter>
  2.       <parameterid>fontname</parameterid>
  3.       <name>Font</name>
  4.       <value>ITC Officina Sans</value>
  5. </parameter>
  6. <parameter>
  7.       <parameterid>fontsize</parameterid>
  8.       <name>Size</name>
  9.       <value>39</value>
  10. </parameter>
  11. <parameter>
  12.       <parameterid>fontstyle</parameterid>
  13.       <name>Style</name>
  14.       <value>1</value>
  15.       </parameter>
  16. <parameter>
  17.       <parameterid>fontalign</parameterid>
  18.       <name>Alignment</name>
  19.       <value>1</value>
  20. </parameter>
  21. <parameter>
  22.       <parameterid>fontcolor</parameterid>
  23.       <name>Font Color</name>
  24.       <value>
  25.             <alpha>255</alpha>
  26.         <red>1</red>
  27.             <green>2</green>
  28.             <blue>3</blue>
  29.       </value>
  30. </parameter>
  31. <parameter>
  32.       <parameterid>origin</parameterid>
  33.       <name>Origin</name>
  34.       <value>
  35.             <horiz>-0.101389</horiz>
  36.             <vert>0.383604</vert>
  37.       </value>
  38. </parameter>

Existing XSL:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">    
  3.     <xsl:output method="xml" indent="yes"/>    
  4.     <xsl:strip-space elements="*"/>    
  5.     <xsl:template match="node()//*">        
  6.         <xsl:if test="normalize-space(.)">            
  7.             <xsl:copy>                
  8.                 <xsl:apply-templates select="@*|node()"/>            
  9.             </xsl:copy>        
  10.         </xsl:if>    
  11.     </xsl:template>    
  12.     <xsl:template match="@*|node()">        
  13.         <xsl:copy>            
  14.             <xsl:apply-templates select="@*|node()"/>        
  15.         </xsl:copy>    
  16.     </xsl:template>
  17. </xsl:stylesheet>
Mar 15 '07
13 2321
dorinbogdan
839 Recognized Expert Contributor
I simplified th XSL to text only "generatori tem[@id='Text']/effect":
[html]<?xml version="1.0"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" standalone="yes " indent="yes"/>

<xsl:strip-space elements="*"/>
<xsl:template match="generato ritem[@id='Text']/effect">
<xsl:copy>
<xsl:copy-of select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>[/html]
and used this similar XML:
[html]<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xmeml.xsl "?>
<xmeml>
<sequence>
<media>
<video>
<track>
<generatorite m id = "Text">
<name>Text1</name>
<effect>
<name>Text2</name>
<parameter>
<parameterid>Te xt3</parameterid>
</parameter>
</effect>
</generatoritem>
</track>
</video>
</media>
</sequence>
</xmeml>[/html]

When open the XML in IE and Firefox, it looks fine.
Apr 5 '07 #11
jtric
7 New Member
Thanks for your response. I must not have been exactly clear, sorry. As I noted earlier, I need to insert two sets of XML tags into two places in the existing XML. The XML tags are held in variables. I think I sort of got it working by changing from xsl: copy-of to xsl: apply-templates in one place... However I have no idea why that works.

I need the transform to insert the two variables ($textinfo and $dropshadow) into <generatorite m id="Text"> and the existing <generatorite m id="Text><effec t>, as well as trip out all of the empty tags.

This (by changing the xsl: copy-of to xsl: apply-templates) works *except* that it strips id="text" from generatoritem.

If I change:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="//generatoritem[@id='Text']">        
  2.         <xsl:copy>            
  3.             <xsl:apply-templates select="*"/>            
  4.             <xsl:copy-of select="$dropshadow"/>
  5.         </xsl:copy>    
  6.     </xsl:template>    
  7.  
to

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="//generatoritem[@id='Text']">        
  2.         <xsl:copy>            
  3.             <xsl:apply-templates select="@*"/>            
  4.             <xsl:copy-of select="$dropshadow"/>
  5.         </xsl:copy>    
  6.     </xsl:template>    
  7.  
It will keep the id="Text", but will not copy the $textinfo variable for some reason?

Appreciate any hints!

Here is the actual full XML and XSL I am working with:

XML
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <xmeml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1">
  3.     <sequence>
  4.         <name>W01144</name>
  5.         <duration>601</duration>
  6.         <rate>
  7.             <ntsc>TRUE</ntsc>
  8.             <timebase>30</timebase>
  9.         </rate>
  10.         <media>
  11.             <video>
  12.                 <track>
  13.                     <clipitem id="5155-20-EINW">
  14.                         <name>5155-20-EINW</name>
  15.                         <duration>601</duration>
  16.                         <in>0</in>
  17.                         <out>601</out>
  18.                         <start>0</start>
  19.                         <end>901</end>
  20.                         <anamorphic>FALSE</anamorphic>
  21.                         <alphatype>none</alphatype>
  22.                         <file id="EINW">
  23.                             <name>EINW</name>
  24.                             <pathurl>file://localhost/Volumes/MediaDrive/Jesse/promos/promo_media/video/5155-20-EINW</pathurl>
  25.                             <duration>601</duration>
  26.                         </file>
  27.                         <filter>
  28.                             <effect>
  29.                                 <name>Basic Motion</name>
  30.                                 <effectid>basic</effectid>
  31.                                 <effectcategory>motion</effectcategory>
  32.                                 <effecttype>motion</effecttype>
  33.                                 <mediatype>video</mediatype>
  34.                                 <parameter>
  35.                                     <parameterid>center</parameterid>
  36.                                     <name>Center</name>
  37.                                     <value>
  38.                                         <horiz>0</horiz>
  39.                                         <vert>0</vert>
  40.                                     </value>
  41.                                 </parameter>
  42.                             </effect>
  43.                         </filter>
  44.                         <sourcetrack>
  45.                             <mediatype>video</mediatype>
  46.                         </sourcetrack>
  47.                     </clipitem>
  48.                     <generatoritem>
  49.                         <effect>
  50.                             <parameter/>
  51.                         </effect>
  52.                         <sourcetrack/>
  53.                     </generatoritem>
  54.                 </track>
  55.                 <track>
  56.                     <clipitem id="WCVWL3">
  57.                         <name>WCVWL3</name>
  58.                         <duration>300</duration>
  59.                         <in>0</in>
  60.                         <out>150</out>
  61.                         <start>751</start>
  62.                         <end>901</end>
  63.                         <anamorphic>FALSE</anamorphic>
  64.                         <alphatype>straight</alphatype>
  65.                         <file id="L3WCVW">
  66.                             <name>L3WCVW</name>
  67.                             <pathurl>file://localhost/Volumes/MediaDrive/Jesse/promos/promo_media/lower3rd/wcvwlower3rd.mov</pathurl>
  68.                             <duration>300</duration>
  69.                         </file>
  70.                         <filter>
  71.                             <effect>
  72.                                 <name>Basic Motion</name>
  73.                                 <effectid>basic</effectid>
  74.                                 <effectcategory>motion</effectcategory>
  75.                                 <effecttype>motion</effecttype>
  76.                                 <mediatype>video</mediatype>
  77.                                 <parameter>
  78.                                     <parameterid>center</parameterid>
  79.                                     <name>Center</name>
  80.                                     <value>
  81.                                         <horiz>0</horiz>
  82.                                         <vert>-0.00205761</vert>
  83.                                     </value>
  84.                                 </parameter>
  85.                             </effect>
  86.                         </filter>
  87.                         <sourcetrack>
  88.                             <mediatype>video</mediatype>
  89.                         </sourcetrack>
  90.                     </clipitem>
  91.                     <generatoritem>
  92.                         <effect>
  93.                             <parameter/>
  94.                         </effect>
  95.                         <sourcetrack/>
  96.                     </generatoritem>
  97.                 </track>
  98.                 <track>
  99.                     <clipitem>
  100.                         <file/>
  101.                         <filter>
  102.                             <effect>
  103.                                 <parameter>
  104.                                     <value/>
  105.                                 </parameter>
  106.                             </effect>
  107.                         </filter>
  108.                         <sourcetrack/>
  109.                     </clipitem>
  110.                     <generatoritem id="Text">
  111.                         <name>Text</name>
  112.                         <duration>3600</duration>
  113.                         <in>1650</in>
  114.                         <out>1776</out>
  115.                         <start>775</start>
  116.                         <end>901</end>
  117.                         <alphatype>black</alphatype>
  118.                         <effect>
  119.                             <name>Text</name>
  120.                             <effectid>Text</effectid>
  121.                             <effectcategory>Text</effectcategory>
  122.                             <effecttype>generator</effecttype>
  123.                             <mediatype>video</mediatype>
  124.                             <parameter>
  125.                                 <parameterid>str</parameterid>
  126.                                 <name>Text</name>
  127.                                 <value>Tonight at 8:00</value>
  128.                             </parameter>
  129.                         </effect>
  130.                         <sourcetrack>
  131.                             <mediatype>video</mediatype>
  132.                         </sourcetrack>
  133.                     </generatoritem>
  134.                 </track>
  135.             </video>
  136.             <audio>
  137.                 <track>
  138.                     <clipitem id="5155-20-EINW">
  139.                         <file id="EINW"/>
  140.                         <sourcetrack>
  141.                             <mediatype>audio</mediatype>
  142.                             <trackindex>1</trackindex>
  143.                         </sourcetrack>
  144.                     </clipitem>
  145.                 </track>
  146.                 <track>
  147.                     <clipitem id="5155-20-EINW">
  148.                         <file id="EINW"/>
  149.                         <sourcetrack>
  150.                             <mediatype>audio</mediatype>
  151.                             <trackindex>2</trackindex>
  152.                         </sourcetrack>
  153.                     </clipitem>
  154.                 </track>
  155.                 <track>
  156.                     <clipitem id="bobby-ton@8">
  157.                         <file id="bobbyton8">
  158.                             <name>bobby-ton@8</name>
  159.                             <pathurl>file://localhost/Volumes/MediaDrive/Jesse/promos/promo_media/voiceovers/bobby-ton@8</pathurl>
  160.                             <duration>125</duration>
  161.                         </file>
  162.                         <in>0</in>
  163.                         <out>125</out>
  164.                         <start>775</start>
  165.                         <end>900</end>
  166.                         <sourcetrack>
  167.                             <mediatype>audio</mediatype>
  168.                             <trackindex>1</trackindex>
  169.                         </sourcetrack>
  170.                     </clipitem>
  171.                 </track>
  172.                 <track>
  173.                     <clipitem id="bobby-ton@8">
  174.                         <file id="bobbyton8"/>
  175.                         <sourcetrack>
  176.                             <mediatype>audio</mediatype>
  177.                             <trackindex>2</trackindex>
  178.                         </sourcetrack>
  179.                     </clipitem>
  180.                 </track>
  181.             </audio>
  182.         </media>
  183.     </sequence>
  184. </xmeml>
  185.  

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">    
  3.     <xsl:output method="xml" encoding="UTF-8" standalone="yes" indent="yes"/>    
  4.     <xsl:variable name="textinfo">            
  5.         <parameter>                
  6.             <parameterid>fontname</parameterid>                
  7.             <name>Font</name>                
  8.             <value>ITC Officina Sans</value>            
  9.         </parameter>            
  10.         <parameter>                
  11.             <parameterid>fontsize</parameterid>                
  12.             <name>Size</name>                
  13.             <value>39</value>            
  14.         </parameter>            
  15.         <parameter>                
  16.             <parameterid>fontstyle</parameterid>                
  17.             <name>Style</name>                
  18.             <value>1</value>            
  19.         </parameter>            
  20.         <parameter>                
  21.             <parameterid>fontalign</parameterid>                
  22.             <name>Alignment</name>                
  23.             <value>1</value>            
  24.         </parameter>            
  25.         <parameter>                
  26.             <parameterid>fontcolor</parameterid>                
  27.             <name>Font Color</name>                
  28.             <value>                    
  29.                 <alpha>255</alpha>                    
  30.                 <red>1</red>                    
  31.                 <green>2</green>                    
  32.                 <blue>3</blue>                
  33.             </value>            
  34.         </parameter>            
  35.         <parameter>                
  36.             <parameterid>origin</parameterid>                
  37.             <name>Origin</name>                
  38.             <value>                    
  39.                 <horiz>-0.101389</horiz>                    
  40.                 <vert>0.383604</vert>                
  41.             </value>            
  42.         </parameter>    
  43.     </xsl:variable>    
  44.     <xsl:variable name="dropshadow">        
  45.         <filter>            
  46.             <effect>                
  47.                 <name>Drop Shadow</name>                
  48.                 <effectid>dropshadow</effectid>                
  49.                 <effectcategory>motion</effectcategory>                
  50.                 <effecttype>motion</effecttype>                
  51.                 <mediatype>video</mediatype>                
  52.                 <parameter>                    
  53.                     <parameterid>offset</parameterid>                    
  54.                     <name>offset</name>                    
  55.                     <value>0</value>                
  56.                 </parameter>                
  57.                 <parameter>                    
  58.                     <parameterid>angle</parameterid>                    
  59.                     <name>angle</name>                    
  60.                     <value>135</value>                
  61.                 </parameter>                
  62.                 <parameter>                    
  63.                     <parameterid>color</parameterid>                    
  64.                     <name>color</name>                    
  65.                     <value>                        
  66.                         <alpha>0</alpha>                        
  67.                         <red>255</red>                        
  68.                         <green>255</green>                        
  69.                         <blue>255</blue>                    
  70.                     </value>                
  71.                 </parameter>                
  72.                 <parameter>                    
  73.                     <parameterid>softness</parameterid>                    
  74.                     <name>softness</name>                    
  75.                     <value>36</value>                
  76.                 </parameter>                
  77.                 <parameter>                    
  78.                     <parameterid>opacity</parameterid>                    
  79.                     <name>opacity</name>                    
  80.                     <value>100</value>                
  81.                 </parameter>            
  82.             </effect>        
  83.         </filter>    
  84.     </xsl:variable>    
  85.     <xsl:strip-space elements="*"/>    
  86.     <xsl:template match="node()//*">        
  87.         <xsl:if test="normalize-space(.)">            
  88.             <xsl:copy>                
  89.                 <xsl:apply-templates select="@*|node()"/>            
  90.             </xsl:copy>        
  91.         </xsl:if>    
  92.     </xsl:template>    
  93.     <xsl:template match="//generatoritem[@id='Text']">        
  94.         <xsl:copy>            
  95.             <xsl:apply-templates select="*"/>            
  96.             <xsl:copy-of select="$dropshadow"/>
  97.         </xsl:copy>    
  98.     </xsl:template>    
  99.     <xsl:template match="//generatoritem[@id='Text']/effect">        
  100.         <xsl:copy>            
  101.             <xsl:apply-templates select="*"/>            
  102.             <xsl:copy-of select="$textinfo"/>        
  103.         </xsl:copy>    
  104.     </xsl:template>    
  105.     <xsl:template match="@*|node()">        
  106.         <xsl:copy>            
  107.             <xsl:apply-templates select="@*|node()"/>        
  108.         </xsl:copy>    
  109.     </xsl:template>
  110. </xsl:stylesheet>
  111.  
Apr 5 '07 #12
dorinbogdan
839 Recognized Expert Contributor
Hmmm, big stuff....

I cannot get enough time today to research deeper.
Eventually, in the XSL, for the 2 variables try to use "value-of" instead of "copy-of" inside of <xsl:copy>.

For more details, see also xsl:copy and xsl:copy-of function reference.

God bless you,
Dorin.
Apr 5 '07 #13
jtric
7 New Member
Hmmm, big stuff....

I cannot get enough time today to research deeper.
Eventually, in the XSL, for the 2 variables try to use "value-of" instead of "copy-of" inside of <xsl:copy>.

For more details, see also xsl:copy and xsl:copy-of function reference.

God bless you,
Dorin.
It has grown a bit more complex than I'd anticipated, mostly because the original XML is exported from Excel and it does not like repeating nested elements. I really appreciate all your help. I will read up on xsl: copy-of and see if I can put it into use.
Apr 5 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1645
by: Willing 2 Learn | last post by:
I'm working on this program below but im stuck. after it finds a match b/ween sentence & non_terminal it will output where these are found in both strings. I need it to spit out the rules with a matching LHS related to that non_terminal; i want to allow the user to select a rule (from # key)they want to use. When the user selects a specified rule; i need to replace the rule in that present address by expanding the non_terminal. I was...
32
3902
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where default_buffer_length is changed from 4 --24 code works fine. But on the same line if I change the value of default_buffer_length from 4 --10 and I get a memory error. And if the change the value of the same variable from 4 --1024 bytes;
3
4243
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been little changed since. However, it works only with an obsolete version of Saxon (6.2.2 I think), and it has a number of small bugs; and I've at last got to the point where I need to fix it. And I'm finding it, frankly, absurdly frustrating and...
6
5796
by: saif.shakeel | last post by:
Hi, I need to replace a string in xml file with something else.Ex - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54"> <SHORTNAME>rate</SHORTNAME> <LONGNAME>rate</LONGNAME> <VALUE role="constant" DataType="unsigned" value="1" /> <BYTEPOSITION role="position" BytePos="1" /> </SERVICEPARAMETER> - <SERVICEPARAMETER id="_776" Semantics="localId" DDORef="_54">
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.