aspose file tools*
The moose likes XML and Related Technologies and the fly likes xhtml to xhtml using xslt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xhtml to xhtml using xslt" Watch "xhtml to xhtml using xslt" New topic
Author

xhtml to xhtml using xslt

Brendan Kennedy
Ranch Hand

Joined: May 02, 2001
Posts: 65
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

Joined: Nov 14, 2000
Posts: 1953
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

Joined: Jan 08, 2001
Posts: 2164
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

Joined: Nov 14, 2000
Posts: 1953
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

Joined: May 02, 2001
Posts: 65
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

Joined: Nov 14, 2000
Posts: 1953
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

Joined: Nov 14, 2000
Posts: 1953
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xhtml to xhtml using xslt
 
Similar Threads
xsl - differentiating nodes
xsl - need to select on attribute and limit output
XSLT merging help
xsl to merge duplicate tag
xsl