SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XSLT and ignoring XML

    Hi,
    I'm a little confused with some XSLT. I have an XML schema that's full of data, but I only need to display some of the data. But it appears that simply "ignoring" XML data will simply just strip the XML tags. Can anyone tell me what I'm not doing right?

    Many thanks,
    Richard

    XSL:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
    	
    	<xsl:template match="order">
         <h1>Order Confirmation</h1>
         
         <p>Congratulations! Your order has been processed and is awaiting
         confirmation. Below is the details of your order. You will also recieve an 
         email confirmation shorltly.</p>	
         
    	  <p>Order <strong><xsl:value-of select="@ref" /></strong></p>
    	   
          <xsl:apply-templates/>	
    	</xsl:template>
       
       
       
    	<xsl:template match="order/itinery">
    		<xsl:variable name="type" select="@type"/>
    		<table border="0" width="100%" cellspacing="1" cellpadding="1">
    			<tr>
    				<td class="lined" width="25"/>
    				<td class="lined">
    					<b>Journey Type</b>
    				</td>
    				<td class="lined">
    					<xsl:if test="$type = 1">
    					One Way
    				</xsl:if>
    					<xsl:if test="$type = 2">
    					Return
    				</xsl:if>
    					<xsl:if test="$type = 3">
    						Multi-Hop
    					</xsl:if>
    				</td>
    			</tr>
    			<tr>
    				<td class="lined" width="25"/>
    				<td class="lined">
    					<b>Subtotal</b>
    				</td>
    				<td class="lined">
    					<xsl:value-of select="@subtotal"/>
    				</td>
    			</tr>
    			<tr>
    				<td class="lined" width="25"/>
    				<td class="lined">
    					<b>Discount</b>
    				</td>
    				<td class="lined">
    				<xsl:choose>
    					<xsl:when test="@discount &lt; 0">
    						<span style="color:red">
    							<xsl:value-of select="@discount"/>
    						</span>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:value-of select="@discount"/>
    					</xsl:otherwise>
    					 </xsl:choose>
    				</td>
    			</tr>
    			<tr>
    				<td class="line2" width="25"/>
    				<td class="line2">
    					<b>Total</b>
    				</td>
    				<td class="line2">
    					<xsl:value-of select="@total"/>
    				</td>
    			</tr>
    		</table>
    		<br/>
    		<!-- Print Hops List -->
    		<table width="100%">
    			<tbody>
    				<tr>
    					<th class="lineHead">Departing From</th>
    					<th class="lineHead">Destination</th>
    				</tr>
    				<xsl:for-each select="hop">
    					<tr>
    						<td>
    						   <address>
    							<xsl:value-of select="sourceAddress/line1"/><br />
    							<xsl:value-of select="sourceAddress/line2"/><br />
    							<xsl:value-of select="sourceAddress/line3"/><br />
    							<xsl:value-of select="sourceAddress/line4"/><br />
    							<xsl:value-of select="sourceAddress/postcode"/><br />
    							<xsl:value-of select="sourceAddress/countryName"/>
    							</address>
    						</td>
    						<td>
    						   <address>
    							<xsl:value-of select="destinationAddress/line1"/><br />
    							<xsl:value-of select="destinationAddress/line2"/><br />
    							<xsl:value-of select="destinationAddress/line3"/><br />
    							<xsl:value-of select="destinationAddress/line4"/><br />
    							<xsl:value-of select="destinationAddress/postcode"/><br />
    							<xsl:value-of select="destinationAddress/countryName"/>
    							</address>
    						</td>
    					</tr>
    				</xsl:for-each>
    			</tbody>
    		</table>
    		<!-- END Print Hops List -->
    		<xsl:apply-templates/>
    	</xsl:template>
    	<xsl:template match="itinery/hop[1]">
    		<h2>Luggage Summary</h2>
    		<table border="0" width="100%" cellpadding="1">
    			<tbody>
    				<tr>
    					<th class="lineHead">Luggage</th>
    					<th class="lineHead">Quantity</th>
    				</tr>
    				<xsl:for-each select="baggage/baggageitem">
    					<tr>
    						<td>
    							<xsl:value-of select="@name"/>
    						</td>
    						<td>
    							<xsl:value-of select="@quantity"/>
    						</td>
    					</tr>
    				</xsl:for-each>
    			</tbody>
    		</table>
    	</xsl:template>	
    </xsl:stylesheet>
    XML:

    HTML Code:
    <order date="06-15-2004" location="302" id="" ref="DZ04302241532">
    -
    	<currency>
    <id>2</id>
    <rate>1.0000</rate>
    <symbol></symbol>
    </currency>
    -
    	<customer id="person1" name="Sulk" surname="The" middlenames="" referrerid="NULL" vatCode="">
    -
    	<sourceAddress>
    <firstname>Sulk</firstname>
    <surname>The</surname>
    <middlenames/>
    <line1>987 Higher Street Than Yours Street</line1>
    <line2/>
    <line3>Worshipmeton</line3>
    <line4/>
    <postcode>?</postcode>
    <country>3</country>
    <countryName>Algeria</countryName>
    </sourceAddress>
    -
    	<billingAddress>
    <firstname>Sulk</firstname>
    <surname>The</surname>
    <middlenames/>
    <line1>987 Higher Street Than Yours Street</line1>
    <line2/>
    <line3>Worshipmeton</line3>
    <line4>Buckinhamshire</line4>
    <postcode>?</postcode>
    <country>3</country>
    <countryName>Algeria</countryName>
    </billingAddress>
    <creditcard type="" number="1111 1111 111" authcode="" expiry="01/2006" start="01/2001" issue="0"/>
    </customer>
    -
    	<lines total="190.00" count="1" currency="2">
    <line id="0" type="1" value="190.00" vat="" vatrate="" quantity="1" total="190.00"/>
    </lines>
    -
    	<itinery id="" type="1" subtotal="190.00" total="190.00" discount="0.00" hops="1">
    -
    	<hop weight="50" bookingref="B3775" id="0">
    -
    	<sourceAddress>
    <firstname>Biatch The</firstname>
    <surname/>
    <middlenames/>
    <line1>47865347856  Holllyhock Terrace</line1>
    <line2>Romford</line2>
    <line3>Appleadayandallthatshire</line3>
    <line4/>
    <postcode>HY4 7PF</postcode>
    <country>98</country>
    <countryName>Hungary</countryName>
    </sourceAddress>
    -
    	<destinationAddress>
    <firstname>Biatch The</firstname>
    <surname/>
    <middlenames/>
    <line1>5852 Ivegotanitchupmy Avenue</line1>
    <line2>5852 Ivegotanitchupmy Avenue</line2>
    <line3>5852 Ivegotanitchupmy Avenue</line3>
    <line4/>
    <postcode>P0K31T</postcode>
    <country>170</country>
    <countryName>Poland</countryName>
    </destinationAddress>
    -
    	<baggage count="2">
    <baggageitem id="9" hop="0" name="Suitcase" quantity="2" weight="25.0"/>
    </baggage>
    </hop>
    </itinery>
    </order>

  2. #2
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is PHP. There is a whole section called "XML and Web Services". Just so you know for next time

  3. #3
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So there is - Thanks

    I did mean to ask though if the arguments passed to the xslt_process function may effect this: At the moment, I simply call

    PHP Code:
    $arguments = array(
        
    '/_xml' => $xml
        
    '/_xsl' => $xsl
    );
                                
    $xh xslt_create();
            
    $result xslt_process($xh'arg:/_xml''arg:/_xsl'NULL$arguments); 
    If not.. then I'll get the post moved..

    -Richard

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An XSL stylesheet will simply not output (in result tree) any tags that it comes across that ain't within the stylesheet as far as I know ?

    That is a convienence which I've used anyways in the past

  5. #5
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a convienience that I'd like to be able to use now..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •