Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xhtml to xhtml using xslt

 
Brendan Kennedy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to use xslt to convert xhtml to xhtml, just changing the attributes of some elements(img and a). It's all going well, except the output I'm getting is all the elements in the order they apear in the origonal. Here is my code:

How can I make it so's the node tree stays the same, with just my changes to the attributes of those elements?
Regards,
Brendan
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just curious, and used your xslt to transform a very simple xhtml file to a new one, and got a totally wrong result. How could it work fine for you.
I'm using xalan transformer...
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its too difficult to look for a solution if one sees only part of the problem.
So you might post your xml input file.
For me the xslt debugger of WSAD is a great help to understand xslt/xPath. XMLSpy seems to have similar feature in their version 5, which is even better because it shows output.
It surely is an efective help for problems like yours.

from xml-spy site:
Step through an XSLT transformation process line-by-line with a 3-panel interface that displays the input XML document (with context node highlighted), the XSLT stylesheet (with current node highlighted), and the output document as it is being built in real-time.

http://www.xmlspy.com/features_xsl.html
Don't know if there are any openSource solutions for that.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use the identity template, and then add specific templates for your specific elements/attributes.
identity template
Good luck!
 
Brendan Kennedy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies
the xsl wasn't working totally fine. it was working ok in that the img tag was getting changed in the way I wanted. The elements were being sorted into the order they apeared in in the origonal file, ie with no children. I'm using xml spy 4.3 and (I think) the msxml parser.
The files I'm using are at :
http://www.redbrick.dcu.ie/~keno/ranch/
The other xsl there is trying it using templates.
I haven't gotten working with the identity template yet, hopefully that does it
Thanks again
Brendan
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The identity template will guarantee you have everything else work correct. You need only to focus on the elements you need to change. Your original code on attribute has a problem, which is that if img tag has width/height/etc. other attributes, they will be lost.
I might try to make it work when I've some time, but it is not a promise.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your answer here:
Q. How to tranform an xhtml file to an identical xhtml with the exceptions of adding prefix path to src/href attribute value?
Try to display the original xhtml to see all the broken images and link. Then use the xslt to tranform it to a new xhtml to see it live and beautiful. I think You would love it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic