[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] [no subject]<aaa><xsl:value-of select=".../aaa"/></aaa> <bbb><xsl:value-of select=".../bbb"/></bbb> <ccc><xsl:value-of select=".../ccc"/></ccc> Or something like it (judging from the "...") If it's simple enough, you can simply do <xsl:copy-of select="aaa|bbb|ccc"/> But I don't think you've told us the whole truth, so it might have to be something like <xsl:if test="...aaa"> <aaa> <xsl:value-of ... </aaa> </xsl:if> etc. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: Ben Stover [mailto:bxstover@xxxxxxxxxxx] > Sent: 07 October 2009 13:10 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: How to copy only the really existing <choice> > branch/element? "value-of-if-exist" > > Assume I have a XML source based on the following > (simplified) XSD schema: > > <xsd:element name="top" type="mytype"/> > > <xsd:complexType name="mytype"> > <xsd:choice> > <xsd:element name="aaa" type="....."> > <xsd:element name="bbb" type="....."> > <xsd:element name="ccc" type="....."> > </xsd:choice> > </xsd:complexType> > > That mean either element aaa or element bbb or element ccc is > filled/exists. > > Now I want to copy only this sub-element to a target which > currently exists. > > If I simply write: > > <xsl:value-of select=".../aaa"/> > <xsl:value-of select=".../bbb"/> > <xsl:value-of select=".../ccc"/> > > then ALL three elements were copied. The 2 branches which do > not exist were created as empty elements so that the target > XML doc looks like e.g. > > <top> > <aaa></aaa> > <bbb>myvalue</bbb> > <ccc></ccc> > </top> > > which is an invalid XML because of its XSD schema file definition. > > The question is now: How can I let XSL copy only this > branch/element which really exists? > I need a function like > > <xsl:value-of-only-the-existing-choice-branch select=..../top"/> > > or > > <xsl:value-of-if-exists select=".../aaa"/> > <xsl:value-of-if-exists select=".../bbb"/> > <xsl:value-of-if-exists select=".../ccc"/> > > How can I do this in detail? > > Thank you > Ben
|
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
|