0
我有一個XSL文件看起來像這樣:價值中不顯示我的XML文件時轉化
<?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"/>",
\t "name":"<xsl:value-of select="name"/>"
"description":"<xsl:value-of select="description"/>",
"Category 1":"<xsl:value-of select="cat1"/>",
\t "Category 2":"<xsl:value-of select="cat2"/>",
\t "Category 3":"<xsl:value-of select="cat3"/>",
\t "Category 4":"<xsl:value-of select="cat4"/>" \t }
</xsl:template>
</xsl:stylesheet>
但是當我運行它在我的XslCompiledTranform-方法VS,我沒有在.json結果文件中返回任何值。
var myXslTrans = new XslCompiledTransform();
myXslTrans.Load("Products.xsl");
myXslTrans.Transform("Products.xml", "result_data_products.json");
這裏是我的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>
這裏是結果以.json格式,其中沒有價值被插入。
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
{ "index":{"_index":"test-product", "_type":"Product"}}
{ "Id":"",
\t "name":""
"description":"",
"Category 1":"",
\t "Category 2":"",
\t "Category 3":"",
\t "Category 4":"" \t }
非常感謝。這就是訣竅! –