次の方法で共有


xsl:namespace-alias Element (Windows Embedded CE 6.0)

1/6/2010

The <xsl:namespace-alias> element replaces the prefix associated with a given name space with another prefix.

Syntax

<xsl:namespace-alias
  stylesheet-prefix = QName
  result-prefix = QName/>

Attributes

None.

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:stylesheet

Child elements

None

Remarks

Sometimes the content that an XSL Transformations (XSLT) file generates is other XSLT. This presents a challenge with name spaces because there is no explicit way to declare two prefixes with the same name space without the processor treating both prefixes as the same name space and acting on them. With the name space-alias command, you canassign an interim name space to an alternate prefix, apply the style sheet, and then map the alternate name space to the XSLT one.

Although XSL-to-XSL file generation is the primary use for this command, it is not the only one. You can use this technique anywhere you have colliding name spaces (for example, with the xsi: schema data type name space). The top-level element must be <xsl:namespace-alias>.

Examples

The following style sheet generates a style sheet based on a couple of input parameters, and then maps the alt: prefix to the xsl: prefix.

alias.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate" 
version="1.0">
<xsl:namespace-alias stylesheet-prefix="alt" result-prefix="xsl"/>
<xsl:param name="browser" select="'InternetExplorer'"/>
  <xsl:template match="/">
     <alt:stylesheet>
     <xsl:choose>
          <xsl:when test="$browser='InternetExplorer'">
          <alt:import href="IERoutines.xsl"/>
          <alt:template match="/">
              <div>
              <alt:call-template name="showTable"/>
              </div>
          </alt:template>
          </xsl:when>
          <xsl:otherwise>
          <alt:import href="OtherBrowserRoutines.xsl"/>
          <alt:template match="/">
              <div>
              <alt:call-template name="showTable"/>
              </div>
          </alt:template>
          </xsl:otherwise>
     </xsl:choose>
     </alt:stylesheet>
  </xsl:template>
</xsl:stylesheet>

The resulting output stylesheet can be viewed by loading it with the following Microsoft® Visual Basic® code.

Sub aliastest(StyleSheetFileName As String)
    Dim DOMDoc As New Msxml2.DOMDocument
    Dim StyleSheet As New Msxml2.DOMDocument
    Dim Output As New Msxml2.DOMDocument

    StyleSheet.Load StyleSheetFileName
    
    DOMDoc.transformNodeToObject StyleSheet, Output
    
    MsgBox Output.xml
End Sub

Private Sub Command1_Click()
       Call aliastest("C:\Code_Snippets\alias.xsl")
End Sub

The following shows the resulting style sheet when the Visual Basic application is run.

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:import
href="IERoutines.xsl"/><xsl:template match="/"><div><xsl:call-template
name="showTable"/></div></xsl:template></xsl:stylesheet>

See Also

Reference

XSLT Elements
xsl:import Element
xsl:include Element