XSL rules applying to XSD (XML schema) defined type names (as opposed to node names)

  • Thread starter Lewis G. Pringle, Jr.
  • Start date
L

Lewis G. Pringle, Jr.

Folks:
I have some XML text I'm tranforming from one schema to another. Both
schemas have their own notion of 'address' (as well as many other contepts).

XSL seems to be mainly suited to transforming XML types based on their
name. For example:

<xsl:template match="user-address">
<xsl:element name="Addr">
<xsl:element name="Addr1"><xsl:value-of select="line-1"/></xsl:element>
<xsl:element name="City"><xsl:value-of select="city"/></xsl:element>
<xsl:element name="StateProvCd"><xsl:value-of
select="state-abbreviation"/></xsl:element>
<xsl:element name="PostalCode"><xsl:value-of select="zip"/></xsl:element>
</xsl:element>
</xsl:template>

This seems to do an admirable job of transforming all instances of
'user-address' in my source XML file into the appropriate contruct in the
destination XML file.

But - my schemas are very complicated, and - for example - have many
addresses. They also have a 'company-address'. The structure of the mapping
is IDENTICAL.

Helpfully - these XML files are already constructed with XML schemas.
And - both schemas have a 'complex-type' declared for these addresses (as in
<xs:complexType name="address-type"><xs:sequence> <xs:element name="line-1"
type="xs:string"/>..... AND <xs:element name="user-address"
type="address-type"/>). So - I hoped to leverage this in my xsl:template.
I've tried LOTS of variations on this - but none seem to work:

<xsl:template match="self[@type='address-type']">
<xsl:element name="Addr">
<xsl:element name="Addr1"><xsl:value-of select="line-1"/></xsl:element>
<xsl:element name="City"><xsl:value-of select="city"/></xsl:element>
<xsl:element name="StateProvCd"><xsl:value-of
select="state-abbreviation"/></xsl:element>
<xsl:element name="PostalCode"><xsl:value-of select="zip"/></xsl:element>
</xsl:element>
</xsl:template>

Unfortunately - this rule never seems to get matched. So - I tried

<xsl:template match="user-address">
<xsl:element name="Addr">
<xsl:element name="SHOW_TYPE"><xsl:value-of
select="@type"/></xsl:element>
</xsl:element>
</xsl:template>

And I was surprised to see no type is output (e.g. <SHOW_TYPE />).

Any clues what maybe going on? Is this a supported thing to do with
XSL? (btw - I've treid using MSXML 4.0 and XERCES - don't remmeber the
version# - but it was recent).

Please reply by email.

Lewis.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top