Subject: RE: [xsl] Data Leakage From: Simon Reed <simon.reed@xxxxxxxxxx> Date: Mon, 26 Mar 2001 17:23:18 +0100 |
That's excellent thanks for the help we're back up and running. Si. -----Original Message----- From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx] Sent: 26 March 2001 16:48 To: Simon Reed Cc: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' Subject: Re: [xsl] Data Leakage 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 ********************************************************************** The information in this E-Mail is confidential and may be legally privileged. It may not represent the views of WebX Limited. It is intended solely for the addressees. Access to this E-Mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Any unauthorised recipient should advise the sender immediately of the error in transmission. ********************************************************************** XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Data Leakage, Jeni Tennison | Thread | [xsl] REMOVE, Brett Harris |
RE: [xsl] passing username, Chris Bayes | Date | RE: [xsl] grouping question, Blake, Stephen |
Month |