|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Need to output an opening or closing tag by itself
I have somewhat similar issue, wherein I had empty element <email/>, which I want to be keep as empty in the resulting xml. Here it looks like: Input: ====== <email url="xxx@xxxxxxx"/> Output requires ================ <email url="xxx@xxxxxxx"/> <fnt> *Email: xxx@xxxxxxx </fnt> Stylesheet ====================== <xsl:template match="email[@url]"> <xsl:copy> <xsl:copy-of select="@*"/> <fnt> <xsl:choose> <xsl:when test="count(ancestor::meta/author)!=1"> <xsl:text>*Corresponding author: Email: </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>*Email: </xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="./@url"/> </fnt> </xsl:copy> </xsl:template> But using the above, I am getting the following, which is not the way I wanted: What I get =========== <email url="xxx@xxxxxxx"> <fnt> *Email: xxx@xxxxxxx </fnt> </email> I am using few other scripting languages after XML transformations, so I've taken care of it their, but I know its not the best way of handling the XML inputs. Best, Pankaj Chaturvedi ============================================================================ ================ -----Original Message----- From: Michael Kay [mailto:mike@xxxxxxxxxxxx] Sent: Wednesday, June 25, 2008 3:04 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: Need to output an opening or closing tag by itself The output of a transformation is a tree of nodes. It is not lexical XML containing angle-bracket tags - those are produced from the result tree by the serializer. Creating a node on the result tree is an atomic operation, you can't create half a node. The problem you are tackling is called positional grouping, In XSLT 2.0 you can often tackle it using <xsl:for-each-group>. In 1.0 an appropriate technique is often sibling recursion, where you process a sequence of siblings one-by-one in a recursive template. You should be able to find these techniques using a google search. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: David Frey [mailto:dpfrey@xxxxxxx] > Sent: 25 June 2008 05:30 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Need to output an opening or closing tag by itself > > I have a simple XSLT problem for the gurus. > > > This is my input document: > <root> > <e t="a"/> > <f/> > <f/> > <e t="b"/> > </root> > > > This is the output document I want to produce: > <root> > <e> > <f/> > <f/> > </e> > </root> > > > This is the stylesheet I wrote to do the transformation: > <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet > version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:template match="/root"> > <root> > <xsl:apply-templates/> > </root> > </xsl:template> > > <xsl:template match="e"> > <xsl:choose> > <xsl:when test="@t ='a'"> > <e> > </xsl:when> > <xsl:when test="@t ='b'"> > </e> > </xsl:when> > <xsl:otherwise> > <xsl:message terminate="yes"> > Unexpected data in attribute t. > </xsl:message> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > <xsl:template match="f"> > <xsl:copy/> > </xsl:template> > </xsl:stylesheet> > > > Here is the Saxon output: > $ java -jar "c:\Program Files\Saxon\saxon9.jar" -o out.xml in.xml > test.xslt Error on line 16 column 9 of > file:/C:/Documents%20and%20Settings/DFREY/Desktop/test/test.xslt: > SXXP0003: Error reported by XML parser: The element type "e" must be > terminated by the > matching end-tag "</e>". > Failed to compile stylesheet. 1 error detected. > > > I understand that the source of the error is that the XSLT file is not > valid XML because the <e> tag doesn't have a matching </e> tag in the > right place. > > How can I work around this issue to solve my problem? > > Thanks, > David Confidentiality Notice:" This message and any attachment(s) contained here are information that is confidential, proprietary to IDS Infotech Ltd. and its customers. Contents may be privileged or otherwise protected by law. The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer."
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








