473,778 Members | 2,804 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 #1
13 2320
dorinbogdan
839 Recognized Expert Contributor
Welcome to TSDN...

I'm not sure what is the desired output.
Please post the final structure you expect to obtain too.
Mar 15 '07 #2
jtric
7 New Member
Welcome to TSDN...

I'm not sure what is the desired output.
Please post the final structure you expect to obtain too.
Thanks!

Sorry, here is the final structure:


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.     <parameter>
  13.                  <parameterid>fontname</parameterid>
  14.                  <name>Font</name>
  15.                  <value>ITC Officina Sans</value>
  16.         </parameter>
  17.         <parameter>
  18.                 <parameterid>fontsize</parameterid>
  19.                 <name>Size</name>
  20.                 <value>39</value>
  21.          </parameter>
  22.          <parameter>
  23.                <parameterid>fontstyle</parameterid>
  24.                <name>Style</name>
  25.                <value>1</value>
  26.          </parameter>
  27.          <parameter>
  28.               <parameterid>fontalign</parameterid>
  29.               <name>Alignment</name>
  30.               <value>1</value>
  31.          </parameter>
  32.          <parameter>
  33.               <parameterid>fontcolor</parameterid>
  34.               <name>Font Color</name>
  35.               <value>
  36.                   <alpha>255</alpha>
  37.               <red>1</red>
  38.                   <green>2</green>
  39.                   <blue>3</blue>
  40.               </value>
  41.          </parameter>
  42.          <parameter>
  43.              <parameterid>origin</parameterid>
  44.               <name>Origin</name>
  45.               <value>
  46.                     <horiz>-0.101389</horiz>
  47.                     <vert>0.383604</vert>
  48.               </value>
  49.           </parameter>
  50. </effect>
  51.  
Mar 15 '07 #3
dorinbogdan
839 Recognized Expert Contributor
So you will use 2 XML files to get the result.
Then you need a merge/concat method.
For the moment I only can point you to some links.
See if
Merge two files or
Merging XML Documents help.
Mar 15 '07 #4
jtric
7 New Member
So you will use 2 XML files to get the result.
Then you need a merge/concat method.
For the moment I only can point you to some links.
See if
Merge two files or
Merging XML Documents help.
Solution two in that link looks like exactly what I need. I will tool around with it.

Thanks for pointing me in the right direction! Will post my solution if I'm able to figure it out.
Mar 15 '07 #5
jtric
7 New Member
Solution two in that link looks like exactly what I need. I will tool around with it.

Thanks for pointing me in the right direction! Will post my solution if I'm able to figure it out.
Not sure who else might benefit from this, but I figured I would post what ended up working. Thanks again for pointing me in the right direction.

(I did not end up needing to use the dummy tag)

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:strip-space elements="*"/>    
  45.     <xsl:template match="node()//*">        
  46.         <xsl:if test="normalize-space(.)">            
  47.             <xsl:copy>                
  48.                 <xsl:apply-templates select="@*|node()"/>            
  49.             </xsl:copy>        
  50.         </xsl:if>    
  51.     </xsl:template>    
  52.     <xsl:template match="//generatoritem/effect">    
  53.         <xsl:copy>    
  54.             <xsl:copy-of select="*"/> 
  55.             <xsl:copy-of select="$textinfo"/> 
  56.         </xsl:copy>    
  57.     </xsl:template>    
  58.     <xsl:template match="@*|node()">        
  59.         <xsl:copy>            
  60.             <xsl:apply-templates select="@*|node()"/>        
  61.         </xsl:copy>    
  62.     </xsl:template>
  63. </xsl:stylesheet>
Mar 16 '07 #6
dorinbogdan
839 Recognized Expert Contributor
Glad to see it is working.

Who knows, sometime it may be helpful for others too.
Mar 19 '07 #7
dorinbogdan
839 Recognized Expert Contributor
Since the problem was solved I'll close the thread.
Mar 21 '07 #8
dorinbogdan
839 Recognized Expert Contributor
I re-open the thread in order to allow further comments or suggestions from other members or experts, as per adim request.
Mar 22 '07 #9
jtric
7 New Member
I'm glad that you re-opened the thread, as I seem to have borked my solution by adding what I thought was a simple modification.

The structure I am working with is essentially this (simplified, but this is the section I need to modify):

Expand|Select|Wrap|Line Numbers
  1. <xmeml>
  2.    <sequence>
  3.        <media>
  4.           <video>
  5.              <track>
  6.                   <generatoritem id = "Text">
  7.                    <name>Text</name>
  8.                    <effect>
  9.                         <name>Text</name>
  10.                         <parameter>
  11.                               <parameterid>Text</parameterid>
  12.                          </parameter>
  13.                    </effect>
  14.                   </generatoritem>
  15.                </track>
  16.            <video>
  17.         <media>
  18.   <sequence>
  19. <xmeml>
I need to insert two sets of tags that are held in variables in my xsl.
One goes in generatoritem/effect
One goes in generatoritem


The previous posts illustrate how I accomplished the former. I added the following to the xslt to accomplish the latter, thinking I understood fully how it worked.

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="generatoritem[@id='Text']">        
  2.         <xsl:copy-of select="*"/>
  3.         <xsl:copy-of select="$dropshadow"/>
  4. </xsl:template>
However, when I add that, nothing gets added to generatoritem/effect and it seems that my generatoritem tags get stripped completely? Perhaps someone could point me in the right direction to fix this?

Thanks in advance for any guidance anyone can offer!

My full xsl is below:

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']/effect">        
  94.         <xsl:copy>            
  95.             <xsl:copy-of select="*"/>            
  96.             <xsl:copy-of select="$textinfo"/>        
  97.         </xsl:copy>    
  98.     </xsl:template>    
  99.     <xsl:template match="generatoritem[@id='Text']">        
  100.         <xsl:copy-of select="*"/>
  101.         <xsl:copy-of select="$dropshadow"/>
  102.     </xsl:template>
  103.     <xsl:template match="@*|node()">        
  104.         <xsl:copy>
  105.             <xsl:apply-templates select="@*|node()"/>
  106.         </xsl:copy>
  107.     </xsl:template>
  108. </xsl:stylesheet>
  109.  
Apr 4 '07 #10

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
3900
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
4242
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
5795
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
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10068
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
9923
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
8954
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...
1
7474
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.