Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

XSLT Help

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am working on an XSL and am facing a problem thats been troubling me for a while. Being new to XSL, this might turn out to be a basic problem... any help would be nice.

Source Document looks like:

<TopLevelTag>
<Level1>
<Lv1Tag0/>
<Lv1Tag1/>
<Lv1Tag2/>
<Lv1Tag3/>
<Lv1Tag4/>
</Level1>
</TopLevelTag>

I want my XSL to work on tags Lv1Tag1, Lv1Tag2, Lv1Tag3 and transform the above to:

<TopLevelTag>
<Level1>
<Lv1Tag1/>
</Level1>
<Level1>
<Lv1Tag2/>
</Level1>
<Level1>
<Lv1Tag3/>
</Level1>
</TopLevelTag>

I tried thinking of using <xsl:for-each> but could not think up a solution. Tried exploring the internet for XPATH options available, but to no avail.

I dont know if it helps, but I tried to see if a regular expression can be used in the XPATH somehow. But, I guess thats more of a XSLT2.0 feature (I have to work on 1.0) & I cannot use that.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Himanshu Jhamb:

I want my XSL to work on tags Lv1Tag1, Lv1Tag2, Lv1Tag3 and transform the above to:

<TopLevelTag>
<Level1>
<Lv1Tag1/>
</Level1>
<Level1>
<Lv1Tag2/>
</Level1>
<Level1>
<Lv1Tag3/>
</Level1>
</TopLevelTag>

I tried thinking of using <xsl:for-each> but could not think up a solution. Tried exploring the internet for XPATH options available, but to no avail.



So, how far did you go with your ideas.....
Please post your style sheet so we know where to start.
I don't want to do all the homework for you.
Thanks.

- m
 
Ranch Hand
Posts: 1241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Himanshu Jhamb:

I tried thinking of using <xsl:for-each> but could not think up a solution. Tried exploring the internet for XPATH options available, but to no avail.



You may want to consider using the xsl:copy-of tag. You could make a template that matches all children of the level1 node, and for each makes a copy of the parent and makes a copy of the current node inside it.

http://www.devguru.com/Technologies/xslt/quickref/xslt_element_copyof.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic