[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Data Leakage

Subject: Re: Data Leakage
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 26 Mar 2001 16:47:56 +0100
xsl attribute max length
Hi Simon,

> I am having a bit of bother with data leakage the xslt seems to pay
> no attention to the pathway in the match statement, the only way to
> lock the data seems to be to use a for - each, I was under the
> impression that the use of applied templates negated the use of
> them. The xslt transforms the xml into item elements with attributes
> which we would then pass through a generic html form builder we have
> built.

The stylesheet that you attached produces simply:

  <form action="" />

The trouble is that the template that matches the root node, is
applying templates to the 'Name', 'DateOfBirth' and so on children of
the root node.  The root node only has one child - the 'document'
element, so none of these xsl:apply-templates instructions find any
nodes to apply templates to, and you get no content.

I think that you want to change this template to match the
'PolicyHolder' element and then have another template that makes sure
that templates are only applied to that 'PolicyHolder' element,
something like:

<xsl:template match="document">
   <xsl:apply-templates select="Policy/PolicyHolder" />
</xsl:template>

I think that if you do this you get the result that you're after.  By
the way, you might find it easier to use attribute value templates
rather than xsl:attribute in order to generate all those attribute
values.  For example, rather than:

>         <xsl:template
> match="CommunicationsChannel[@type='Telephone']|CommunicationsChannel[@type=
> 'Fax']" mode="TelFax">
>                 <item type="telephone">
>                         <xsl:attribute name="title">
>                                 <xsl:value-of select="PhoneType"/>
>                         </xsl:attribute>
>                         <xsl:attribute name="name">
>                                 <xsl:value-of select="PhoneType"/>
>                         </xsl:attribute>
>                         <xsl:attribute name="Cc">
>                                 <xsl:value-of select="CountryCode"/>
>                         </xsl:attribute>
>                         <xsl:attribute name="Ac">
>                                 <xsl:value-of select="AreaCode"/>
>                         </xsl:attribute>
>                         <xsl:attribute name="Telephone">
>                                 <xsl:value-of select="TelephoneNumber"/>
>                         </xsl:attribute>
>                 </item>
>         </xsl:template>

You could use:

<xsl:template match="CommunicationsChannel" mode="TelFax">
   <item type="telephone"
         title="{PhoneType}" name="{PhoneType}"
         Cc="{CountryCode}" Ac="{AreaCode}"
         Telephone="{TelephoneNumber}" />
</xsl:template>

Note that the only CommunicationsChannel elements that have templates
applied to them in TelFax mode are those that have a @type of
'Telephone' or 'Fax', so there's no need to check this in the match
pattern.

You may also find it worthwhile defining the form elements (e.g. their
size and title) in a separate piece of XML and then using that as the
basis of the item elements that you're creating.  For example, you
could create a document like this:

--- items.xml ---
<items>
<item type="text" title="Title" name="Title"
      size="5" maxlength="25" />
<item type="text" title="First Name" name="Forename"
      size="8" maxlength="50" />
<item type="text" title="Middle Name" name="Middlename"
      size="8" maxlength="50" />
<item type="text" title="Last Name" name="Surname"
      size="8" maxlength="50" />
<item type="text" title="Suffix" name="Suffix"
      size="8" maxlength="50" />
<item type="text" title="DateOfBirth" name="DateOfBirth"
      size="10" maxlength="50" />
...
</items>
---

You can get all the item elements into a variable with the document()
function:

<xsl:variable name="items"
              select="document('items.xml')/items/item" />

Then, given an element, then you can get the relevant item element
with the XPath:

  $items[@name = name($element)]

You can then copy it, copy its attributes, and add the value attribute
to it giving the value of the element. Thus, all those templates
dealing with the separate elements get compressed down into one:

<xsl:template match="*">
   <xsl:variable name="element" select="." />
   <xsl:for-each select="$items[@name = name($element)]">
      <xsl:copy>
         <xsl:copy-of select="@*" />
         <xsl:attribute name="value">
            <xsl:value-of select="$element" />
         </xsl:attribute>
      </xsl:copy>
   </xsl:for-each>
</xsl:template>

If you prefer, rather than an xsl:for-each you can apply templates to
the item, passing the element along as a parameter:

<xsl:template match="*">
   <xsl:apply-templates select="$items[@name = name(current())]">
      <xsl:with-param name="element" select="current()" />
   </xsl:apply-templates>
</xsl:template>

<xsl:template match="item">
   <xsl:param name="element" />
   <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:attribute name="value">
         <xsl:value-of select="$element" />
      </xsl:attribute>
   </xsl:copy>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • Data Leakage
    • Simon Reed - Mon, 26 Mar 2001 09:30:33 -0500 (EST)
      • Jeni Tennison - Mon, 26 Mar 2001 10:48:43 -0500 (EST) <=
      • <Possible follow-ups>
      • Simon Reed - Mon, 26 Mar 2001 11:24:56 -0500 (EST)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.