简体   繁体   English

转换后的价值不会显示i XML文件

[英]Value-of in won't show i XML file when transformed

I have a XSL file that looks like this: 我有一个看起来像这样的XSL文件:

 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.loc.gov/mods/v3"> <xsl:output method="text" encoding="UTF-8" media-type="text/plain"/> <xsl:template match="/"> <!-- Fetch all products --> <xsl:apply-templates select="Data/Products" /> </xsl:template> <xsl:template match="Products"> { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"<xsl:value-of select="Id"/>", "name":"<xsl:value-of select="name"/>" "description":"<xsl:value-of select="description"/>", "Category 1":"<xsl:value-of select="cat1"/>", "Category 2":"<xsl:value-of select="cat2"/>", "Category 3":"<xsl:value-of select="cat3"/>", "Category 4":"<xsl:value-of select="cat4"/>" } </xsl:template> </xsl:stylesheet> 

But when I run it in my XslCompiledTranform-method in VS, I don't get any values back in the .json result file. 但是,当我在VS的XslCompiledTranform方法中运行它时,.json结果文件中没有任何值。

 var myXslTrans = new XslCompiledTransform(); myXslTrans.Load("Products.xsl"); myXslTrans.Transform("Products.xml", "result_data_products.json"); 

Here is my XML file: 这是我的XML文件:

 <?xml version="1.0" encoding="utf-8"?> <Data> <Products Id="1" name="Golf1" description="En langsom golf bil" cat1="Bil" cat2="VW" cat3="Golf" cat4="1" /> <Products Id="2" name="Golf2" description="En knap så langsom golf bil. Faktisk er den næsten hurtig." cat1="Bil" cat2="VW" cat3="Golf" cat4="2" /> <Products Id="3" name="Golf3" description="Det er ikke en golf. Det er et billede af en golf. Bil medfølger." cat1="Bil" cat2="VW" cat3="Golf" cat4="3" /> <Products Id="4" name="Golf4" description="Den aller hurtigste bil. Hurtigere end en langsommere." cat1="Bil" cat2="VW" cat3="Golf" cat4="4" /> <Products Id="5" name="7 jern" description="God kølle til tæsk og golf." cat1="Sport" cat2="Golf" cat3="Køller" cat4="" /> <Products Id="6" name="19 jern" description="God til golf. Dårlig til tæsk." cat1="Sport" cat2="Golf" cat3="Køller" cat4="" /> <Products Id="7" name="Golfbold" description="Rund golfbold" cat1="Sport" cat2="Golf" cat3="Bolde" cat4="Hvid" /> <Products Id="8" name="Golfbold" description="Noget man slår til med sin kølle." cat1="Sport" cat2="Golf" cat3="Bolde" cat4="Sort" /> </Data> 

And here is the result in .json format, where no value is inserted. 这是.json格式的结果,其中未插入任何值。

  { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } { "index":{"_index":"test-product", "_type":"Product"}} { "Id":"", "name":"" "description":"", "Category 1":"", "Category 2":"", "Category 3":"", "Category 4":"" } 

要选择属性,您需要例如<xsl:value-of select="@Id"/>而不是<xsl:value-of select="Id"/>因此您需要更改所有这些路径。

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

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