【问题标题】:creating a xaml with xslt使用 xslt 创建 xaml
【发布时间】:2011-07-26 09:30:54
【问题描述】:

我正在尝试创建 xaml Line 元素的 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>

问题:

  • 有没有更好的方法来管理这些命名空间
  • 参数 $xOne、$xTwo、... 不起作用。据我所知,xslt 我应该像这样实现它们:&lt;xsl:value-of select="number($xOne)"/&gt; 但这是不可能的,因为我尝试实现它们的方式。

我希望有更多xslt和xaml经验的人可以帮助我? :)

我使用的是 xsl v1.0

提前。

【问题讨论】:

    标签: xml xaml xslt namespaces


    【解决方案1】:

    有没有更好的方法来管理这些命名空间?

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

    <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>
    

    如果不使用前缀,将考虑默认命名空间。


    参数 $xOne, $xTwo, ... 不起作用

    了解AVT并使用:

    X1="{$xOne}"
    

    【讨论】:

      【解决方案2】:

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

      <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"
      >
      

      那么你可以简单地编写,而不添加命名空间:

      <Line
      

      使用{}设置属性值,例如:

      <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>
      

      【讨论】:

        猜你喜欢
        • 2014-09-26
        • 1970-01-01
        • 2015-01-17
        • 2014-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-23
        • 1970-01-01
        相关资源
        最近更新 更多