This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: outputing elements correctly .
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] outputing elements correctly .
- From: "Michael Kay" <mhkay at iclway dot co dot uk>
- Date: Thu, 13 Sep 2001 15:31:14 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
> If i use
> templates in my stylesheet,the output of the elements
> is correct but without the optional elements i also
> want to output with their default values.
Template rules can only match elements that are present; there is no way of
getting a template rule to fire if something is absent.
> ... and the other one which doesn't
> work correctly. Can someone please tell me what i'm
> doing wrong ?
It looks OK to me, for example
> <xsl:when test="AMD:pickingSequence">
> <xsl:variable name="pseq" select="."/>
> <xsl:number value="$pseq" format="00"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
should output 00 if the element is absent, and indeed it does.
In fact, the stylesheet appears to do exactly what you say you want. If this
isn't what you actually want, then you need to describe your requirements
more clearly.
(Of course you can simplify lines 2+3 to <xsl:number value="." format="00"/>
Mike Kay
>
> Thanks.
> Auguste
>
> Xml-file:
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <articleMasterData
> xmlns="http://www.Artikelstammdaten.org"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://www.Artikelstammdaten.org
> ArticleMaDaSch.xsd">
>
> <?xml-stylesheet type="text/xsl"
> href="ArticleMaDaXmlToHtml.xsl"?>
> <?xml-stylesheet type="text/xsl"
> href="ArticleMaDaXmlToAscii.xsl"?>
>
> <telegramNumber>001100</telegramNumber>
> <client>123</client>
> <articleNumber>123456oumar</articleNumber>
> <itemCode>Hamburg-Germany</itemCode>
>
> <quantityPerPackingUnit>12345678</quantityPerPackingUnit>
> <QPPU-Modus>4</QPPU-Modus>
> <batchMode>5</batchMode>
> <quantityUnit>Pa</quantityUnit>
> <deliveryReferenz>00000089</deliveryReferenz>
> <price>134</price>
> <weight>65</weight>
> <height>15</height>
> <width>00000767</width>
> <depth>00000987</depth>
> <bestBeforeDate>20</bestBeforeDate>
> <pickingSequence>7</pickingSequence>
> <actionCode>2</actionCode>
> </articleMasterData>
>
> Stylesheet with templates:
>
> <?xml version="1.0" encoding="ISO8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
> xmlns:AMD="http://www.Artikelstammdaten.org"
> xmlns="http://www.w3.org/TR/REC-html40">
>
> <xsl:output method="text"/>
> <xsl:strip-space elements="*"/>
>
> <xsl:template match="/">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="AMD:articleMasterData">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="AMD:telegramNumber">
> <xsl:value-of select="."/></xsl:template>
>
> <xsl:template match="AMD:client">
> <xsl:variable name="mandant" select="."/>
> <xsl:number value="$mandant"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:articleNumber">
> <xsl:variable name="arNbr" select="."/>
> <xsl:value-of select="substring(concat($arNbr,'
> '),1,20)"/></xsl:template>
>
>
> <xsl:template match="AMD:itemCode">
> <xsl:variable name="iCode" select="."/>
> <xsl:value-of select="substring(concat($iCode,'
> '),1,30)"/></xsl:template>
>
> <xsl:template match="AMD:itemCode2">
> <xsl:variable name="iCode2" select="."/>
> <xsl:value-of select ="substring(concat($iCode2,'
>
> '),1,50)"/></xsl:template>
>
>
> <xsl:template match="AMD:quantityPerPackingUnit">
> <xsl:variable name="qppu" select="."/>
> <xsl:number value="$qppu"
> format="00000000"/></xsl:template>
>
>
> <xsl:template match="AMD:QPPU-Modus">
> <xsl:value-of select="."/></xsl:template>
>
> <xsl:template match="AMD:batchMode">
> <xsl:value-of select="."/></xsl:template>
>
> <xsl:template match="AMD:quantityUnit">
> <xsl:variable name="qUnit" select="."/>
> <xsl:value-of select="substring(concat($qUnit,'
> '),1,2)"/></xsl:template>
>
> <xsl:template match="AMD:deliveryReferenz">
> <xsl:variable name="dRef" select="."/>
> <xsl:value-of select="substring(concat($dRef,'
> '),1,8)"/></xsl:template>
>
> <xsl:template match="AMD:price">
> <xsl:variable name="prix" select="."/>
> <xsl:number value="$prix"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:weight">
> <xsl:variable name="poids" select="."/>
> <xsl:number value="$poids"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:height">
> <xsl:variable name="haut" select="."/>
> <xsl:number value="$haut"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:width">
> <xsl:variable name="largeur" select="."/>
> <xsl:number value="$largeur"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:depth">
> <xsl:variable name="profondeur" select="."/>
> <xsl:number value="$profondeur"
> format="00000000"/></xsl:template>
>
> <xsl:template match="AMD:bestBeforeDate">
> <xsl:variable name="bbDate" select="."/>
> <xsl:number value="$bbDate"
> format="0000"/></xsl:template>
>
> <xsl:template match="AMD:pickingSequence">
> <xsl:variable name="pseq" select="."/>
> <xsl:number value="$pseq"
> format="00"/></xsl:template>
>
> <xsl:template match="AMD:actionCode">
> <xsl:value-of select="."/></xsl:template>
>
> </xsl:stylesheet>
>
> stylesheet without template(doesn't work properly):
>
> <?xml version="1.0" encoding="ISO8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
> xmlns:AMD="http://www.Artikelstammdaten.org"
> xmlns="http://www.w3.org/TR/REC-html40">
>
> <xsl:output method="text"/>
> <xsl:strip-space elements="*"/>
>
> <xsl:template match="/">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="AMD:articleMasterData">
> <xsl:if test="AMD:telegramNumber">
> <xsl:value-of select="."/>
> </xsl:if>
> <xsl:if test="AMD:client">
> <xsl:variable name="mandant" select="."/>
> <xsl:number value="$mandant" format="00000000"/>
> </xsl:if>
> <xsl:if test="AMD:articleNumber">
> <xsl:variable name="arNbr" select="."/>
> <xsl:value-of select="substring(concat($arNbr,'
> '),1,20)"/>
> </xsl:if>
> <xsl:if test="AMD:itemCode">
> <xsl:variable name="iCode" select="."/>
> <xsl:value-of select="substring(concat($iCode,'
> '),1,30)"/>
> </xsl:if>
> <xsl:choose>
> <xsl:when test="AMD:itemCode2">
> <xsl:variable name="iCode2" select="."/>
> <xsl:value-of select ="substring(concat($iCode2,'
>
> '),1,50)"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>
> </xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:choose>
> <xsl:when test="AMD:quantityPerPackingUnit">
> <xsl:variable name="qppu" select="."/>
> <xsl:number value="$qppu" format="00000000"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00000000</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:if test="AMD:QPPU-Modus">
> <xsl:value-of select="."/>
> </xsl:if>
> <xsl:if test="AMD:batchMode">
> <xsl:value-of select="."/>
> </xsl:if>
> <xsl:if test="AMD:quantityUnit">
> <xsl:variable name="qUnit" select="."/>
> <xsl:value-of select="substring(concat($qUnit,'
> '),1,2)"/>
> </xsl:if>
> <xsl:choose>
> <xsl:when test="AMD:deliveryReferenz">
> <xsl:variable name="dRef" select="."/>
> <xsl:value-of select="substring(concat($dRef,'
> '),1,8)"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text> </xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:if test="AMD:price">
> <xsl:variable name="prix" select="."/>
> <xsl:number value="$prix" format="00000000"/>
> </xsl:if>
> <xsl:choose>
> <xsl:when test="AMD:weight">
> <xsl:variable name="poids" select="."/>
> <xsl:number value="$poids" format="00000000"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00000000</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:choose>
> <xsl:when test="AMD:height">
> <xsl:variable name="haut" select="."/>
> <xsl:number value="$haut" format="00000000"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00000000</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:choose>
> <xsl:when test="AMD:width">
> <xsl:variable name="largeur" select="."/>
> <xsl:number value="$largeur" format="00000000"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00000000</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:choose>
> <xsl:when test="AMD:depth">
> <xsl:variable name="profondeur" select="."/>
> <xsl:number value="$profondeur" format="00000000"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00000000</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> <xsl:if test="AMD:bestBeforeDate">
> <xsl:variable name="bbDate" select="."/>
> <xsl:number value="$bbDate" format="0000"/>
> </xsl:if>
> <xsl:choose>
> <xsl:when test="AMD:pickingSequence">
> <xsl:variable name="pseq" select="."/>
> <xsl:number value="$pseq" format="00"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:text>00</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
>
> <xsl:if test="AMD:actionCode">
> <xsl:value-of select="."/>
> </xsl:if>
>
> </xsl:template>
> </xsl:stylesheet>
>
>
>
>
> __________________________________________________________________
> Do You Yahoo!?
> Gesendet von Yahoo! Mail - http://mail.yahoo.de
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list