1

I'm constructing a XML schema with XSLT using just one specific value from the input schema. My goal is to construct a generic xslt for other documents.

Here is my input xsd simplified :

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nr0="http://NamespaceTest.com/balisesXrm" xmlns:xalan="http://xml.apache.org/xslt" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo" xmlns="urn:SBEGestionZonesAeriennesSYSCA-schema" xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema" SCCOAMCD:desc="  implémentation du MCD pivot du SCCOA 3.2.1ec  production par SCCOA mcd2mpd 4.1.1, le 11/12/2007  règles spécifiques production schémas 1.2  diagramme : A-SC.SBE GestionZonesAeriennes SYSCA  entité racine      : A-SC.ZoneAerienne " attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:SBEGestionZonesAeriennesSYSCA-schema" version="3.2.1ec">

<xsd:element name="SBEGestionZonesAeriennesSYSCA" type="SBEGestionZonesAeriennesSYSCA:type_SBEGestionZonesAeriennesSYSCA"/>

<xsd:schema>

I writted this xslt :

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
xmlns:err="http://www.w3.org/2005/xqt-errors"
exclude-result-prefixes="xsd xdt err fn"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
extension-element-prefixes="redirect"
xmlns:xalan="http://xml.apache.org/xslt">

<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>

<xsl:template match="xsd:schema">
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SBEGestionZonesAeriennesSYSCA="urn:SBEGestionZonesAeriennesSYSCA-schema"
xmlns:xrm="http://www.moss.fr/2011/connecteur_xrm" xmlns:nr0="http://NamespaceTest.com/balisesXrm" xmlns:SCCOAMCD="urn:SCCOA-schemaInfo" xmlns:metier="urn:SBEGestionZonesAeriennesSYSCA-schema"  targetNamespace="http://www.moss.fr/2011/connecteur_xrm" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xsl:call-template name="importbalisesXrm"/>
        <xsl:call-template name="importNamespaceXrm"/>
        <xsl:apply-templates/>
        <xsl:call-template name="mapping"/>
    </xsd:schema>
</xsl:template>

<xsl:template name="mapping">
<xsd:complexType name="mapping">
        <xsd:sequence>
            <xsd:element ref="{xsd:element/@name}" namespace="urn:SBEGestionZonesAeriennesSYSCA-schema"/>
        </xsd:sequence>
        <xsd:attribute name="occurs"></xsd:attribute>
    </xsd:complexType>
</xsl:template>
</xsl:stylesheet>

My problem is with this instruction, the output XSD gives me ref="SBEGestionZonesAeriennesSYSCA" while i would like ref="metier:SBEGestionZonesAeriennesSYSCA". Hope someone has an idea to add a prefix with the value-of command.

1 Answer 1

3

Currently you do this...

<xsd:element ref="{xsd:element/@name}" ... />

But Attribute Value Templates don't need to take up the whole of the attribute value. You can just do this...

<xsd:element ref="metier:{xsd:element/@name}" ... />

An alternative would be to do this, but this is not as concise

<xsd:element ref="{concat('metier:', xsd:element/@name)}" ... />

For future reference, you can use as many AVTs as you want, so this would be valid, for example, although rather excessive

 <xsl:variable name="prefix" select="'metier'" />
 <xsd:element ref="{$prefix}:{xsd:element/@name}" ... />
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I didn't realize that it was that simple... Should i delete my post?
It's only simple once you know the answer :). But I think in this case, it may genuinely benefit other newcomers to XSLT, so it is worth keeping the question.
Definitely keep your question and @TimC's answer for the benefit of future readers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.