This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: multiple documents, namespaces and the same structure
- To: davidc at nag dot co dot uk (David Carlisle)
- Subject: Re: [xsl] multiple documents, namespaces and the same structure
- From: Dan Vint <dvint at slip dot net>
- Date: Wed, 10 Jan 2001 13:40:35 -0800 (PST)
- Cc: xsl-list at lists dot mulberrytech dot com, dvint at slip dot net
- Reply-To: xsl-list at lists dot mulberrytech dot com
Well this gave me the direction I needed, but here is the implementation as
callable templates:
<xsl:for-each select="//commercial:business/commercial:us.address">
<xsl:call-template name="format.address">
<xsl:with-param name="address.node" select="."/>
</xsl:call-template>
</xsl:for-each>
notice I don't need the local-name() stuff here because this particular
stylesheet is only dealing with the information from "commercial"
so the template looks like:
<xsl:template name="format.address">
<xsl:param name="address.node"/>
<xsl:text>
</xsl:text>
<xsl:choose>
<xsl:when test="$address.node/@address.type='street'">
<!-- Do nothing in this case -->
</xsl:when>
<xsl:when test="$address.node/@address.type='ship'">
<tr>
<td width="10"> </td>
<td colspan="3">
<span class="{$subheading}">Shipping Address</span>
</td>
</tr>
</xsl:when>
<xsl:when test="$address.node/@address.type='mail' and normalize-space(.) != ''">
<tr>
<td width="10"> </td>
<td colspan="3">
<span class="{$subheading}">Mailing Address</span>
</td>
</tr>
</xsl:when>
</xsl:choose>
<xsl:call-template name="test.and.print">
<xsl:with-param name="label">Street address:</xsl:with-param>
<xsl:with-param name="value" select="$address.node/*[local-name(.)='street'][1]"/>
</xsl:call-template>
<xsl:call-template name="test.and.print">
<xsl:with-param name="label">Street address 2:</xsl:with-param>
<xsl:with-param name="value" select="$address.node/*[local-name(.)='street'][2]"/>
</xsl:call-template>
<xsl:call-template name="test.and.print">
<xsl:with-param name="label">City:</xsl:with-param>
<xsl:with-param name="value" select="$address.node/*[local-name(.)='city']"/>
</xsl:call-template>
<xsl:call-template name="test.and.print">
<xsl:with-param name="label">State:</xsl:with-param>
<xsl:with-param name="value" select="$address.node/*[local-name(.)='state']"/>
</xsl:call-template>
<xsl:call-template name="test.and.print">
<xsl:with-param name="label">ZIP:</xsl:with-param>
<xsl:with-param name="value">
<xsl:value-of select="$address.node/*[local-name(.)='zip']/@main"/>
<xsl:if test="$address.node/*[local-name(.)='zip']/@sub != ''">-<xsl:value-of select="$address.node/*[local-name(.)='zip']/@sub"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
It is here in this template that I need to capture the element name seperate
from the prefixed value so this is where the local-name() is really required
because I have address info coming from documents with several different
namespaces/prefixes.
notice the one little twist for the use of street, this is actually a repeating
element in our address model.
thanks again.
..dan
>
>
> Equivalent to what you said you had would be
>
> <xsl:for-each
> select="//*[local-name(.)='business']/*[local-name(.)='us.address']">
>
> <xsl:value-of select="."/>
> <xsl:value-of select="@address.type"/>
> <!-- see below <xsl:value-of select="*[local-name(.)='street']"/>-->
> <xsl:value-of select="street"/>
>
> </xsl:for-each>
>
> which would work for any namespace as long as the local names were as
> given.
>
> but that would seem to produce a strange output.
>
> Given
> <us.address address.type="street">
> <street>222 Kearney St.</street>
> <street>Suite 500</street>
> <city>San Francisco</city>
> <state>CA</state><zip main="94108" sub="1234"/>
> </us.address>
>
> your template
>
>
> <xsl:template name="format.address">
> <xsl:param name="address.node"/>
> <xsl:value-of select="$address.node"/>
> <xsl:value-of select="$address.node/@address.type"/>
> <xsl:value-of select="$address.node/street"/>
> </xsl:template>
>
> surely produces
>
> 222 Kearney St.Suite 500San FranciscoCAstreet222 Kearney St.Suite 500
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> $address.node
> ^^^^^^
> $address.node/@address.type
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> $address.node/street
>
> As you can see, you can use local-name() to make a template apply to any
> namespace, but if these address constructs mean the same thing in
> different files why are they in different namespaces? It would be more
> in the spirit of the game if you placed common elements in a common
> namespace.
>
> Oh actually you don't get the street name twice, as
> <xsl:value-of select="$address.node/street"/>
> presumably never selects anything as there isn't an element street in
> the null namespace. it's always in the namespace attatched to (for
> example) commercial:
>
> so your example produces
>
> 222 Kearney St.Suite 500San FranciscoCAstreet
>
> no?
>
>
> David
>
> _____________________________________________________________________
> This message has been checked for all known viruses by Star Internet delivered
> through the MessageLabs Virus Control Centre. For further information visit
> http://www.star.net.uk/stats.asp
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list