简体   繁体   English

xslt值-未被解析

[英]xslt value-of not being parsed

I am trying to generate several text files, depending of number of object elements present in input XML document. 我试图生成多个文本文件,具体取决于输入XML文档中存在的对象元素的数量。 For this purpose I am using result-document() (xslt 2.0) function, and transformations are evaluated by Saxon. 为此,我使用result-document() (xslt 2.0)函数,并且转换由Saxon进行评估。

For some reason, when running the transformation in Saxon, I am not getting values from some xsl:value-of functions, but when I run standard XSLT debug (I need to comment out the xsl:result-document function) in VS 2010 Ultimate, I am getting expected result.The problem is rooted in FillTheObjectFromForm templates xsl:for-each loop. 出于某种原因,在Saxon中运行转换时,我没有从某些xsl:value-of函数获取值,而是在VS 2010 Ultimate中运行标准XSLT调试(我需要注释掉xsl:result-document函数)时,我得到了预期的结果。问题根源于FillTheObjectFromForm模板xsl:for-each循环。

Can someone please point out what is wrong in my template? 有人可以指出我的模板出了什么问题吗?

To keep this post short, I've uploaded XML and result files to http://hotfile.com . 为了简短起见,我已将XML和结果文件上传到http://hotfile.com Here are code samples and input XML: 以下是代码示例和输入XML:

XML: XML:

<?xml version="1.0" encoding="utf-8"?>
<dbs:MetaDataRoot FreeForm="true" xmlns:dbs="http://stefan/DbStructure">  
  <orm:MappingRoot FreeForm="False" MapDataStructure="ASPBaza" TransactionType="ADONET" Namespace="GeneratedCode" xmlns:orm="http://stefan/ORM.xsd">
    <orm:Build MapDataStructure="ASPBaza" />
    <orm:Assembly Namespace="GeneratedCode" MapDataStructure="ASPBaza" Name="BusinessLayer"> 
      <orm:Objects>
        <orm:Object  OriginalName="Kupac" Name="Kupac" TableName="Kupac" CollectionName="Kupac" Caption="Kupac" >          
          <orm:Properties>
            <orm:Property Name="SifraKupca"  IsPrimaryKey="true" ControlType="System.Windows.Forms.TextBox" ControlPrefix="txt"  ControlName="txtSifraKupca" BindProperty="Text" Display="false"></orm:Property>
            <orm:Property Name="Ime" IsPrimaryKey="false" ControlPrefix="txt"  ControlName="txtIme" BindProperty="Text" Display="true"></orm:Property>
            <orm:Property Name="Prezime"  IsPrimaryKey="false"  ControlPrefix="txt" ControlName="txtPrezime" BindProperty="Text" Display="true"></orm:Property>
            <orm:Property Name="BrojTelefona" IsPrimaryKey="false"  ControlPrefix="txt" ControlName="txtBrojTelefona" BindProperty="Text" Display="true"></orm:Property>
            <orm:Property Name="Adresa" IsPrimaryKey="false" ControlPrefix="txt"  ControlName="txtAdresa" BindProperty="Text" Display="true"></orm:Property>
          </orm:Properties>
          <orm:AllProperties />
        </orm:Object>
        ...
        </orm:Objects>
        </orm:Assembly>
        </orm:MappingRoot>
</dbs:MetaDataRoot>

XSLT: XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                exclude-result-prefixes="msxsl"
                xmlns:orm="http://stefan/ORM.xsd"
                xmlns:ui="http://stefan/UserInterface">
    <xsl:output method="text" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates 
               select="//orm:Assembly//orm:Objects" 
               mode="Object"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="orm:Objects" mode="Object">

        <xsl:for-each select="orm:Object">
            <xsl:variable name="dirname" 
              select ="'..\..\UI\FinalResultWebUIDesignClasses\'"/>
            <xsl:variable name="filename" 
               select="concat($dirname,@Name,'Edit','.aspx.cs')"/>
            <xsl:result-document method="text" href="{$filename}"> 
                <xsl:call-template name ="SaveButtonEvent"/>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="SaveButtonEvent">

        protected void SaveButtonEvent(object sender, EventArgs e)
        {
        MiddletierManager mm = new MiddletierManager();
        <xsl:value-of select="@Name"/> objectClass = new <xsl:value-of select="@Name"/>();
        <xsl:call-template name="FillTheObjectFromForm"/>
        mm.Save(objectClass);
        }
    </xsl:template>
    <xsl:template name="FillTheObjectFromForm">
        <xsl:for-each select="orm:Properties/*">
            objectClass.<xsl:value-of select="@Name"/> = this.<xsl:choose>
                <xsl:when test ="@ControlPrefix = 'txt' and @IsPrimaryKey='false'">
                    <xsl:value-of select="@ControlName"/>.<xsl:value-of select="@BindProperty"/>;
                </xsl:when>
                <xsl:when test ="@ControlPrefix = 'txt' and @IsPrimaryKey='true'">hdnID.Value;</xsl:when>
                <xsl:when test="@ControlPrefix ='cbo'">
                    <xsl:value-of select="@ControlName"/>.<xsl:value-of select="@BindProperty"/>;
                </xsl:when>
                <xsl:when test="@ControlPrefix ='dtp'">
                    <xsl:value-of select="@ControlName"/>.Value;
                </xsl:when>
                <xsl:when test="@ControlPrefix ='chk'">
                    <xsl:value-of select="@ControlName"/>.Checked;
                </xsl:when>
            </xsl:choose>            
        </xsl:for-each>
    </xsl:template>   
</xsl:stylesheet>

SAXON code used to parse the XSLT: code file 用于解析XSLT的SAXON代码: 代码文件

Here is the sample representing expected and actual transformation results: 这是代表预期和实际转换结果的示例:

Actual results: 实际结果:

protected void SaveButtonEvent(object sender, EventArgs e)
        {
        MiddletierManager mm = new MiddletierManager();
        Korpa objectClass = new Korpa();

            objectClass.KorpaID = this.
            objectClass.SifraKupca = this.
            objectClass.Datum = this.
        mm.Save(objectClass);
        }

Expected results: 预期成绩:

protected void SaveButtonEvent(object sender, EventArgs e)
        {
        MiddletierManager mm = new MiddletierManager();
        Korpa objectClass = new Korpa();

            objectClass.KorpaID = this.hdnID.Value;
            objectClass.SifraKupca = this.SelectedValue;

            objectClass.Datum = this.dtpDatum.Value;

        mm.Save(objectClass);
        }

I have run your stylesheet (only edited the file name assignment) 我已经运行了您的样式表(仅编辑了文件名分配)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                exclude-result-prefixes="msxsl"
                xmlns:orm="http://stefan/ORM.xsd"
                xmlns:ui="http://stefan/UserInterface">
    <xsl:output method="text" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates 
               select="//orm:Assembly//orm:Objects" 
               mode="Object"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="orm:Objects" mode="Object">

        <xsl:for-each select="orm:Object">
            <xsl:variable name="dirname" 
              select ="'..\..\UI\FinalResultWebUIDesignClasses\'"/>
            <xsl:variable name="filename" 
               select="concat(@Name,'Edit','.aspx.cs')"/>
            <xsl:result-document method="text" href="{$filename}"> 
                <xsl:call-template name ="SaveButtonEvent"/>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="SaveButtonEvent">

        protected void SaveButtonEvent(object sender, EventArgs e)
        {
        MiddletierManager mm = new MiddletierManager();
        <xsl:value-of select="@Name"/> objectClass = new <xsl:value-of select="@Name"/>();
        <xsl:call-template name="FillTheObjectFromForm"/>
        mm.Save(objectClass);
        }
    </xsl:template>
    <xsl:template name="FillTheObjectFromForm">
        <xsl:for-each select="orm:Properties/*">
            objectClass.<xsl:value-of select="@Name"/> = this.<xsl:choose>
                <xsl:when test ="@ControlPrefix = 'txt' and @IsPrimaryKey='false'">
                    <xsl:value-of select="@ControlName"/>.<xsl:value-of select="@BindProperty"/>;
                </xsl:when>
                <xsl:when test ="@ControlPrefix = 'txt' and @IsPrimaryKey='true'">hdnID.Value;</xsl:when>
                <xsl:when test="@ControlPrefix ='cbo'">
                    <xsl:value-of select="@ControlName"/>.<xsl:value-of select="@BindProperty"/>;
                </xsl:when>
                <xsl:when test="@ControlPrefix ='dtp'">
                    <xsl:value-of select="@ControlName"/>.Value;
                </xsl:when>
                <xsl:when test="@ControlPrefix ='chk'">
                    <xsl:value-of select="@ControlName"/>.Checked;
                </xsl:when>
            </xsl:choose>            
        </xsl:for-each>
    </xsl:template>   
</xsl:stylesheet>

with Saxon 9.5 HE Java against the input you have shown in your post and the result is KupacEdit.aspx.cs with the contents 使用Saxon 9.5 HE Java反对您在帖子中显示的输入,结果是带有内容的KupacEdit.aspx.cs

protected void SaveButtonEvent(object sender, EventArgs e)
{
MiddletierManager mm = new MiddletierManager();
Kupac objectClass = new Kupac();

    objectClass.SifraKupca = this.hdnID.Value;
    objectClass.Ime = this.txtIme.Text;

    objectClass.Prezime = this.txtPrezime.Text;

    objectClass.BrojTelefona = this.txtBrojTelefona.Text;

    objectClass.Adresa = this.txtAdresa.Text;

mm.Save(objectClass);
}

So I can't reproduce the problem. 因此,我无法重现该问题。 Are you sure the attributes you are trying to output exist in the input sample when the result is missing those values? 当结果缺少这些值时,您确定要尝试输出的属性存在于输入样本中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM