2

ソース スキーマで定義されているすべての Float および Double データ型を 10 進数データ型に変換する必要があります。

サード パーティから XML ドキュメントを取得し、それを XML 構造に変換する既存の XSLT があり、それを 4GL DB アプリケーションに渡すことができます。ネイティブ 4GL インターフェイスの優れた点は、受信 XML をネイティブ データセット構造に変換できることです。短い欠点は、Float および Double データ型を文字データ型にマップすることです。

XSLT 内で Float/Double データ型の要素を識別し、10 進数に変換する方法はありますか。これはメインの XSLT の前のステップであり、出力をメインの XSLT に渡すことができると考えていました。

サンプル スキーマ:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="ttPTManifest">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="JobCode"/>
                <xs:element ref="EstimateHours"/>
                <xs:element ref="ActualHours"/>
                <xs:element ref="Density"/>
                <xs:element ref="NettLitres"/>
                <xs:element ref="QuitOutLitres"/>
                <xs:element ref="QuitInLitres"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="QuitOutLitres" type="xs:double"/>
    <xs:element name="QuitInLitres" type="xs:float"/>
    <xs:element name="PTManifestSonicIn">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="ttPTManifest"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="JobCode" type="xs:string"/>
    <xs:element name="NettLitres" type="xs:double"/>
    <xs:element name="EstimateHours" type="xs:float"/>
    <xs:element name="Density" type="xs:decimal"/>
    <xs:element name="ActualHours" type="xs:float"/>
</xs:schema>

XML データのサンプル:

<?xml version="1.0"?>
<PTManifestSonicIn xsi:noNamespaceSchemaLocation="SampleIn.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ttPTManifest>
        <JobCode>000123</JobCode>
        <EstimateHours>3.14159E3</EstimateHours>
        <ActualHours>3.14159E3</ActualHours>
        <Density>123.456</Density>
        <NettLitres>3.14159265358979E3</NettLitres>
        <QuitOutLitres>3.14159265358979E3</QuitOutLitres>
        <QuitInLitres>3.14159E3</QuitInLitres>
    </ttPTManifest>
</PTManifestSonicIn>

必要なスキーマアウト:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="ttPTManifest">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="JobCode"/>
                <xs:element ref="EstimateHours"/>
                <xs:element ref="ActualHours"/>
                <xs:element ref="Density"/>
                <xs:element ref="NettLitres"/>
                <xs:element ref="QuitOutLitres"/>
                <xs:element ref="QuitInLitres"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="QuitOutLitres" type="xs:decimal"/>
    <xs:element name="QuitInLitres" type="xs:decimal"/>
    <xs:element name="PTManifestSonicIn">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="ttPTManifest"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="JobCode" type="xs:string"/>
    <xs:element name="NettLitres" type="xs:decimal"/>
    <xs:element name="EstimateHours" type="xs:decimal"/>
    <xs:element name="Density" type="xs:decimal"/>
    <xs:element name="ActualHours" type="xs:decimal"/>
</xs:schema>

必要な XML データ出力:

<?xml version="1.0"?>
<PTManifestSonicIn xsi:noNamespaceSchemaLocation="SampleOut.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ttPTManifest>
        <JobCode>000123</JobCode>
        <EstimateHours>3141.59</EstimateHours>
        <ActualHours>3141.59</ActualHours>
        <Density>123.456</Density>
        <NettLitres>3141.59265358979</NettLitres>
        <QuitOutLitres>3141.59265358979</QuitOutLitres>
        <QuitInLitres>3141.59</QuitInLitres>
    </ttPTManifest>
</PTManifestSonicIn>
4

2 に答える 2

1

XSL v2を使用できる場合は、Madsの回答を使用してください。v1で立ち往生している場合、これによりXSD変換を実行できます。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="xs:element[@type='xs:double' or @type='xs:float']">
        <xsl:copy>
            <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
            <xsl:attribute name="type">xs:decimal</xsl:attribute>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

そして、これを使用してXMLを変換できます。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">
    <xsl:output indent="yes"/>

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

    <xsl:template 
          match="*
                  [local-name(.)=document(/*/@xsi:noNamespaceSchemaLocation)/*/xs:element[@type='xs:double' or @type='xs:float']/@name]
                  [number(.)=number(.)]">
        <xsl:copy>
            <xsl:value-of select="number(.)"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
于 2012-09-19T09:01:52.473 に答える
1

XML データを変換するには、次のスタイルシートを使用できます。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="2.0">
    <xsl:output indent="yes"/>

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

    <xsl:template 
           match="*
                  [local-name(.)=document(/*/@xsi:noNamespaceSchemaLocation)/*/xs:element[@type=('xs:double', 'xs:float')]/@name]
                  [. castable as xs:double or . castable as xs:float]">
        <xsl:copy>
            <xsl:value-of select="number(.)"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

次のスタイルシートを使用してスキーマを変換できます。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="2.0">
    <xsl:output indent="yes"/>

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

    <xsl:template match="@type[.=('xs:double', 'xs:float')]">
        <xsl:attribute name="type" select="'xs:decimal'"/>
    </xsl:template>

</xsl:stylesheet>
于 2012-09-19T00:14:33.697 に答える