gpt4 book ai didi

c# - XSLt.transform 给我 ""

转载 作者:数据小太阳 更新时间:2023-10-29 02:23:04 26 4
gpt4 key购买 nike

我有 XML:

<results>
<Countries country="Albania">
<Regions region="Centralna Albania">
<Provinces province="Durres i okolice">
<Cities city="Durres"
cityCode="2B66E0ACFAEF78734E3AF1194BFA6F8DEC4C5760">
<IndividualFlagsWithForObjects Status="1" />
<IndividualFlagsWithForObjects Status="0" />
<IndividualFlagsWithForObjects status="2" />
</Cities>
</Provinces>
</Regions>
</Countries>
<Countries ....

这是这部分查询的结果:

SELECT Countries.FileSystemName as country,
Regions.DefaultName as region ,
Provinces.DefaultName as province,
cities.defaultname as city,
cities.code as cityCode,
IndividualFlagsWithForObjects.value as Status

我有 xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1"/>

<xsl:param name="delim" select="string(',')" />
<xsl:param name="quote" select="string('&quot;')" />
<xsl:param name="break" select="string('&#xD;')" />

<xsl:template match="/">
<xsl:apply-templates select="results/countries" />
</xsl:template>

<xsl:template match="countries">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*">
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(.), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="text()" />
</xsl:stylesheet>

并且是代码的一部分

XmlReader reader = cmd.ExecuteXmlReader();

doc.LoadXml("<results></results>");
XmlNode newNode = doc.ReadNode(reader);

while (newNode != null)
{
doc.DocumentElement.AppendChild(newNode);
newNode = doc.ReadNode(reader);
}

doc.Save(@"c:\listOfCities.xml");

XslCompiledTransform XSLT = new XslCompiledTransform();
XsltSettings settings = new XsltSettings();


XSLT.Load(@"c:\xsltfile1.xslt", settings, new XmlUrlResolver());

XSLT.Transform(doc.OuterXml,@"c:\myCities.csv");

为什么现在我的 csv 中只有一个单元格有值:

最佳答案

输入的 xml(或 xslt)可能以 Unicode 的字节顺序标记开头,并且被 c# 严重解析(我找不到明显的原因......)。

在一些十六进制编辑器中打开它,查看前 3 个字节,然后删除它们。

关于c# - XSLt.transform 给我 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2787615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com