Jim_Cross
October 29th, 2003, 04:49 PM
Hi,
I'm currently trying to use XSLT to reformat an XML file.
The XML file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://dbnexus.risk.db.com/schema/DM_DB_INDUSTRY_NACE_CODES" version="1" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:dbn="http://dbnexus.risk.db.com/schema/dbnexus">
<import namespace="http://dbnexus.risk.db.com/schema/dbnexus" schemaLocation="http://dbnexus.risk.db.com/schema/dbnexus.xsd"/>
<element name="DM_DB_INDUSTRY_NACE_CODES">
<annotation>
<appinfo>
<uniqueconstraint>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
</uniqueconstraint>
<hierarchydisplay>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/BUBA_NACE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/NACE_DESC"/>
</hierarchydisplay>
<index>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/BUBA_NACE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/NACE_DESC"/>
</index>
<defaultsort>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
</defaultsort>
<shortname>DM_DB_INDUSTRY_NACE_CODES</shortname>
</appinfo>
</annotation>
<complexType>
<sequence>
<!-- append user attributes and elements here -->
<element maxOccurs="1" minOccurs="1" name="DB_INDUSTRY_CODE" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="10"/>
</restriction>
</simpleType>
</element>
<element maxOccurs="1" minOccurs="1" name="BUBA_NACE" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="3"/>
</restriction>
</simpleType>
</element>
<element maxOccurs="1" minOccurs="1" name="NACE_DESC" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="255"/>
</restriction>
</simpleType>
</element>
</sequence>
<attributeGroup ref="dbn:versionAttributes"/>
<attributeGroup ref="dbn:idAttributes"/>
</complexType>
</element>
</schema>
What I want to do is firstly select the first element, so something with it, the do something different to all the sub-elements.
However, I can't seem to match the elements in the document. For example, the following code simply prints out "Found node!" a lot, without ever printing "Found element":
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="node()">
<xsl:text>Found node!</xsl:text>
<xsl:text> | </xsl:text>
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="element">
<xsl:text>Found element!</xsl:text>
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
The same happens if I try to match "schema", "schema/element" etc.
Any suggestions as to where I'm going wrong?
Thanks
Jim
I'm currently trying to use XSLT to reformat an XML file.
The XML file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://dbnexus.risk.db.com/schema/DM_DB_INDUSTRY_NACE_CODES" version="1" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:dbn="http://dbnexus.risk.db.com/schema/dbnexus">
<import namespace="http://dbnexus.risk.db.com/schema/dbnexus" schemaLocation="http://dbnexus.risk.db.com/schema/dbnexus.xsd"/>
<element name="DM_DB_INDUSTRY_NACE_CODES">
<annotation>
<appinfo>
<uniqueconstraint>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
</uniqueconstraint>
<hierarchydisplay>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/BUBA_NACE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/NACE_DESC"/>
</hierarchydisplay>
<index>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/BUBA_NACE"/>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/NACE_DESC"/>
</index>
<defaultsort>
<xpath value="/DM_DB_INDUSTRY_NACE_CODES/DB_INDUSTRY_CODE"/>
</defaultsort>
<shortname>DM_DB_INDUSTRY_NACE_CODES</shortname>
</appinfo>
</annotation>
<complexType>
<sequence>
<!-- append user attributes and elements here -->
<element maxOccurs="1" minOccurs="1" name="DB_INDUSTRY_CODE" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="10"/>
</restriction>
</simpleType>
</element>
<element maxOccurs="1" minOccurs="1" name="BUBA_NACE" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="3"/>
</restriction>
</simpleType>
</element>
<element maxOccurs="1" minOccurs="1" name="NACE_DESC" nillable="false">
<simpleType>
<restriction base="string">
<minLength value="1"/>
<maxLength value="255"/>
</restriction>
</simpleType>
</element>
</sequence>
<attributeGroup ref="dbn:versionAttributes"/>
<attributeGroup ref="dbn:idAttributes"/>
</complexType>
</element>
</schema>
What I want to do is firstly select the first element, so something with it, the do something different to all the sub-elements.
However, I can't seem to match the elements in the document. For example, the following code simply prints out "Found node!" a lot, without ever printing "Found element":
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="node()">
<xsl:text>Found node!</xsl:text>
<xsl:text> | </xsl:text>
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="element">
<xsl:text>Found element!</xsl:text>
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
The same happens if I try to match "schema", "schema/element" etc.
Any suggestions as to where I'm going wrong?
Thanks
Jim