我有一个看起来像这样的 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:param name="month"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()">
<xsl:with-param name="month" select="$month"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="month">
<xsl:param name="month"/>
<month>
<xsl:choose>
<xsl:when test="$month">
<xsl:value-of select="$month"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</month>
</xsl:template>
<xsl:template name="splitMonths">
<xsl:param name="months"/>
<xsl:variable name="firstMonth" select="substring-before($months,',')"/>
<xsl:variable name="month">
<xsl:choose>
<xsl:when test="$firstMonth">
<xsl:value-of select="$firstMonth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$months"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="otherMonths" select="substring-after($months,',')"/>
<xsl:if test="$month">
<xsl:apply-templates>
<xsl:with-param name="month" select="$month"/>
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$otherMonths">
<xsl:call-template name="splitMonths">
<xsl:with-param name="months" select="$otherMonths"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="payload">
<payload>
<xsl:call-template name="splitMonths">
<xsl:with-param name="months" select="sets/month"/>
</xsl:call-template>
</payload>
</xsl:template>
</xsl:stylesheet>
这是输入:
<?xml version="1.0" encoding="UTF8"?>
<Response xmlns="http://www.castiron.com/response">
<code>0</code>
<message>Success</message>
<payload>
<sets>
<month>AUG,SEP,OCT,NOV,DEC,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC,JAN</month>
<season>Season11</season>
<productId>11111</productId>
</sets>
</payload>
</Response>
由于 <Response xmlns="http://www.castiron.com/response"> 中的 namespace 标记这会导致整个 XSLT 失败。是否可以取消 namespace 以便 XSLT 工作。如果您删除命名空间并运行 XSLT,它将完美运行!
最佳答案
在 XSLT 中定义命名空间,iep>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:r="http://www.castiron.com/response" exclude-result-prefixes="r">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:param name="month"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()">
<xsl:with-param name="month" select="$month"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="r:month">
<xsl:param name="month"/>
<month xmlns="http://www.castiron.com/response">
<xsl:choose>
<xsl:when test="$month">
<xsl:value-of select="$month"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</month>
</xsl:template>
<xsl:template name="splitMonths">
<xsl:param name="months"/>
<xsl:variable name="firstMonth" select="substring-before($months,',')"/>
<xsl:variable name="month">
<xsl:choose>
<xsl:when test="$firstMonth">
<xsl:value-of select="$firstMonth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$months"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="otherMonths" select="substring-after($months,',')"/>
<xsl:if test="$month">
<xsl:apply-templates>
<xsl:with-param name="month" select="$month"/>
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$otherMonths">
<xsl:call-template name="splitMonths">
<xsl:with-param name="months" select="$otherMonths"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="r:payload">
<payload xmlns="http://www.castiron.com/response">
<xsl:call-template name="splitMonths">
<xsl:with-param name="months" select="r:sets/r:month"/>
</xsl:call-template>
</payload>
</xsl:template>
</xsl:stylesheet>
关于xml - 命名空间停止 XSLT 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9886520/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall
我们目前正在为ROR3.2开发自定义cms引擎。在这个过程中,我们希望成为我们的rails应用程序中的一等公民的几个类类型起源,这意味着它们应该驻留在应用程序的app文件夹下,它是插件。目前我们有以下类型:数据源数据类型查看我在app文件夹下创建了多个目录来保存这些:应用/数据源应用/数据类型应用/View更多类型将随之而来,我有点担心应用程序文件夹被这么多目录污染。因此,我想将它们移动到一个子目录/模块中,该子目录/模块包含cms定义的所有类型。所有类都应位于MyCms命名空间内,目录布局应如下所示:应用程序/my_cms/data_source应用程序/my_cms/data_ty