•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the XML, XSLT and XPATH section within the Software Development category of DaniWeb, a massive community of 375,202 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,316 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our XML, XSLT and XPATH advertiser:
Views: 553 | Replies: 0
![]() |
•
•
Join Date: Nov 2006
Posts: 36
Reputation:
Rep Power: 2
Solved Threads: 1
Hey guys i have a xml file which looks like
i have an xslt that is supposed to take all the elements and make them attributes.
the final looks like
but i want the <required.....> not to have required anmore but just move up to <booking....> and then the additional still there as a element under booking
i dont know where im going wrong can some one help
<?xml version="1.0" ?> - <Booking> - <booking> - <required> <VoyageID>navid</VoyageID> <BookingNumber>omid</BookingNumber> <LoadPort>nariman</LoadPort> <DischargePort>mojedeh</DischargePort> </required> - <additional> <sepandar>sepandar</sepandar> <sepand>sepand</sepand> <manoucher>manoucher</manoucher> <nasrin>nasrin</nasrin> <homa>homa</homa> <parviz>parviz</parviz> <farhad>farhad</farhad> <giti>giti</giti> <marzbani>marzbani</marzbani> </additional> </booking> - <booking> - <required> <VoyageID>2</VoyageID> <BookingNumber>141</BookingNumber> <LoadPort>280</LoadPort> <DischargePort>419</DischargePort> </required> - <additional> <sepandar>558</sepandar> <sepand>697</sepand> <manoucher>836</manoucher> <nasrin>975</nasrin> <homa>1114</homa> <parviz>1253</parviz> <farhad>1392</farhad> <giti>1531</giti> <marzbani>1670</marzbani> </additional> </Booking>
i have an xslt that is supposed to take all the elements and make them attributes.
the final looks like
<?xml version="1.0" encoding="utf-8" ?> - <Booking> - <booking> <required VoyageID="2" BookingNumber="21" LoadPort="30" DischargePort="49" /> <additional sepandar="68" sepand="87" manoucher="106" nasrin="125" homa="144" parviz="163" farhad="182" giti="201" marzbani="220" /> </booking> - <booking> <required VoyageID="3" BookingNumber="12" LoadPort="31" DischargePort="50" /> <additional sepandar="69" sepand="88" manoucher="107" nasrin="126" homa="145" parviz="164" farhad="183" giti="202" marzbani="221" /> </booking> </Booking>
i dont know where im going wrong can some one help
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="copy.xslt"/>
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"/>
<!-- Match elements that are parents -->
<xsl:template match="*[*]">
<xsl:choose>
<!-- Only convert children if this element has no attributes -->
<!-- of its own -->
<xsl:when test="not(@*)">
<xsl:copy>
<!-- Convert children to attributes if the child has -->
<!-- no children or attributes and has a unique name -->
<!-- amoung its siblings -->
<xsl:for-each select="*">
<xsl:choose>
<xsl:when test="not(*) and not(@*) and
not(preceding-sibling::*[name( ) =
name(current( ))])
and
not(following-sibling::*[name( ) =
name(current( ))])">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb XML, XSLT and XPATH Marketplace
- XML Management (RSS, Web Services and SOAP)
- Zend PHP Certification (PHP)
- please take a look at my site... (Website Reviews)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: value-of select and <h1> tag
- Next Thread: can i update variable using concat and for-each?


Linear Mode