[oXygen-user] Syntax problem with xslt 'contains' text()

G. Ken Holman gkholman at CraneSoftwrights.com
Tue Jun 12 12:56:09 CDT 2012


At 2012-06-12 18:44 +0100, McGibbney, Lewis John wrote:
>In particular I wish to grab every occurrence of an <xs:element> 
>where the substitutionGroup value is equal to "ifc:IfcBuildingElement"
>
>I've been using the following xsl code and it is not working.
>
><?xml version="1.0" encoding="UTF-8"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
>     xmlns:ifc="http://www.iai-tech.org/ifcXML/IFC2x3/FINAL"
>     exclude-result-prefixes="xs xd"
>     version="2.0">
>     <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
>     <xsl:strip-space elements="*"/>
>
>     <xsl:template name="main" match="/">
>         <xsl:for-each select="xs:schema/xs:element">
>             <xsl:if test="@substitutionGroup[contains(text(), 
> ifc:IfcBuildingElement)]">

Above you are asking to compare a text node with the child element 
named IfcBuildingElement in the namespace associated with the ifc 
prefix.  Two problems:  attribute nodes never contain text node 
children, and you are asking for the content of a child element 
rather than simple text.

Do you not just want the following?

   <xsl:if test="contains(@substitution,'ifc:IfcBuildingElement')">

But up above you say "is equal to" so that means you could probably 
live with a simple string comparison (which does nothing about string 
normalization):

   <xsl:if test="@substitution='ifc:IfcBuildingElement'">

Note this does not accommodate namespsce prefix dereferencing ... you 
are just checking for a string.  Which is what I think you are asking for.

>                     <xsl:value-of select="xs:schema/xs:element"/>

At this point you are addressing an xs:schema child of the previously 
selected xs:element, which is also wrong ... I suspect you don't want 
to walk away from the element you just tested.

Do you want the element's name?  You are asking for the string value 
of the element's descendants and I don't think you want that.  That 
will always just be white space in the schema.

Did you want to copy the element declarations?  If so you could have:

   <xsl:copy-of select="xs:schema/
             xs:element[@substitutionGroup='ifc:IfcBuildingElement']"/>

>It would be great if someone could point out to me either the 
>incorrect syntax or the absence of the correct configuration.

I hope this helps.  If you could find some basic instruction on XPath 
nodes and node addressing, it would help you to understand where you 
went wrong.

. . . . . . . . . Ken


--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/m/
G. Ken Holman                   mailto:gkholman at CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal



More information about the oXygen-user mailing list