Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2011, 09:15 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default identity transform excluding xml element

Hello,

I am trying identity transformation which will also exclude one of the element with it's value. However, the template was not getting match and output xml file still contains excluded element. Can you please suggest what's gone wrong in the below sample xslt

sample xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="oh"/>

</xsl:stylesheet>

input xml:
<ts-ut id="09" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>

output xml:
<ts-ut id="09" dttyp="x-text/html" rstyp="str">
<sr>
Dwnld Cter
</sr>
<tg>
</tg>

Thanks.
 
Old November 2nd, 2011, 09:27 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

It is hard to tell what goes wrong as neither your input "XML" nor your output "XML" is well-formed.
When I use Saxon 9.3 with the stylesheet
Code:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="oh"/>

</xsl:stylesheet>
and the input
Code:
<ts-ut id="09" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>
</ts-ut>
the result is
Code:
<ts-ut id="09" dttyp="x-text/html" rstyp="str">
   <sr>Dwnld Cter</sr>
   <tg/>
</ts-ut>
where the "oh" elements are removed.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 2nd, 2011, 10:19 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using oxygen xml editor with saxon9.3pe and when i transform i received output xml file with excluded xml element. does something goes wrong in the configuration?

Thanks.
 
Old November 2nd, 2011, 11:15 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Until you give us reliable information about what your input looks like, we can't tell you what's going wrong.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 3rd, 2011, 08:53 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

It seems you are tryinng to exclude the element 'oh', and its excluded in the output as Martin has mentioned. Please let us know the exact element you want to exclude from the output.
__________________
Rummy
 
Old November 8th, 2011, 07:07 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for delay! the input xml file looks like below...

<?xml version="1.0" encoding="utf-8"?>
<xliff>
<file>
<header/>
<body>
<ts-ut id="01" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>
</ts-ut>
<ts-ut id="02" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>
</ts-ut>
<ts-ut id="03" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>
</ts-ut>
<ts-ut id="04" dttyp="x-text/html" rstyp="str">
<sr>
<oh id="1" x="b">{1}</oh>Dwnld Cter<oh id="2" x="b">{2}</oh>
</sr>
<tg>
<oh id="1" x="b">{1}</oh>
<oh id="2" x="b">{2}</oh>
</tg>
</ts-ut>
</body>
</file>
</xliff>
 
Old November 8th, 2011, 07:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You keep showing us the input, and the output you ARE getting, but you've yet to show us the output you WANT to see, as we can't tell from your description what the exact issue is.

Please show us what you want the output to look like.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 8th, 2011, 07:51 AM
Authorized User
 
Join Date: Apr 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Output file will be without excluded element like....
<?xml version="1.0" encoding="utf-8"?>
<xliff>
<file>
<header/>
<body>
<ts-ut id="01" dttyp="x-text/html" rstyp="str">
<sr>
Dwnld Cter
</sr>
<tg>
</tg>
</ts-ut>
<ts-ut id="02" dttyp="x-text/html" rstyp="str">
<sr>
Dwnld Cter
</sr>
<tg>
</tg>
</ts-ut>
<ts-ut id="03" dttyp="x-text/html" rstyp="str">
<sr>
Dwnld Cter
</sr>
<tg>
</tg>
</ts-ut>
<ts-ut id="04" dttyp="x-text/html" rstyp="str">
<sr>
Dwnld Cter
</sr>
<tg>
</tg>
</ts-ut>
</body>
</file>
</xliff>
 
Old November 8th, 2011, 08:04 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

If you have tried with Martin's code, you would have got the expected output. Check please.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform Attribute based xml to element based xml pallone XSLT 6 February 2nd, 2016 07:59 AM
identity transform excluding xml element ShaileshShinde BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 1 November 2nd, 2011 09:22 AM
XSL sort on identity transform imshriram XSLT 1 October 14th, 2011 03:57 PM
XSLT output to HTML - xml element text should look exactly as laid out in xml element DjGogga XSLT 4 July 21st, 2011 05:39 PM
Getting @@IDENTITY in Row Transform afward SQL Server DTS 2 September 28th, 2005 09:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.