Xml 使用xslt创建xaml

Xml 使用xslt创建xaml,xml,xaml,xslt,namespaces,Xml,Xaml,Xslt,Namespaces,我正在尝试创建xaml行元素的xsl模板 这就是我到目前为止所做的: ... <xsl:call-template name="Line"> <xsl:with-param name="xOne" select="70"/> <xsl:with-param name="xTwo" select="905"/> <xsl:with-param name="yOne" select="500"/> <xsl:with-para

我正在尝试创建xaml行元素的xsl模板

这就是我到目前为止所做的:

... 

<xsl:call-template name="Line">
  <xsl:with-param name="xOne" select="70"/>
  <xsl:with-param name="xTwo" select="905"/>
  <xsl:with-param name="yOne" select="500"/>
  <xsl:with-param name="yTwo" select="500"/>
</xsl:call-template>

<xsl:template name="Line">
    <xsl:param name="xOne"/>
    <xsl:param name="xTwo"/>
    <xsl:param name="yOne"/>
    <xsl:param name="yTwo"/>
    <Line xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Stroke="red"
      StrokeThickness="2"
      X1="$xOne"
      X2="$xTwo"
      Y1="<xsl:value-of select="number($yOne)"/>" <!-- example: not working -->
      Y2="$yTwo"/>
</xsl:template>
。。。

您可以将命名空间声明放在根节点中,即:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
有没有更好的方法来管理这些名称空间?

可以将命名空间声明添加到样式表根元素:

<xsl:stylesheet version="1.0" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="Line">
    <xsl:param name="xOne"/>
    <xsl:param name="xTwo"/>
    <xsl:param name="yOne"/>
    <xsl:param name="yTwo"/>
    <Line
        Stroke="red"
        StrokeThickness="2"
        X1="{$xOne}"
        X2="{$xTwo}"
        Y1="{$yOne}"
    Y2="{$yTwo}"/>
</xsl:template>
<xsl:stylesheet version="1.0" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="Line">
    <!-- ... -->
    <x:Line />
</xsl:template>
X1="{$xOne}"