XML1
<?xml version="1.0" encoding="utf-8"?>
<root type="array">
<persons>
<person_id>_:genid1</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is a very long string</oneof>
</oneofs>
</persons>
<persons>
<person_id>_:genid108</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is another very long string</oneof>
</oneofs>
</persons>
</root>
XML2
<?xml version="1.0" encoding="utf-8"?>
<root type="array">
<persons>
<person_id>_:genid1</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is </oneof>
<oneofagain>a very long string</oneofagain>
</oneofs>
</persons>
<persons>
<person_id>_:genid108</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is </oneof>
<oneofagain>another very long string</oneofagain>
</oneofs>
</persons>
</root>
答案 0 :(得分:1)
这是一个非常广泛的问题,但也许这会有所帮助......
XML输入
<root type="array">
<persons>
<person_id>_:genid1</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is a very long string</oneof>
</oneofs>
</persons>
<persons>
<person_id>_:genid108</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is another very long string</oneof>
</oneofs>
</persons>
</root>
XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<!--Identity template-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="oneof">
<xsl:call-template name="split">
<xsl:with-param name="input" select="."/>
<xsl:with-param name="name" select="local-name()"/>
<xsl:with-param name="length" select="10"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="split">
<xsl:param name="input"/>
<xsl:param name="name"/>
<xsl:param name="length"/>
<xsl:variable name="remaining" select="substring($input, $length + 1)"/>
<xsl:element name="{$name}">
<xsl:value-of select="substring($input, 1, $length)"/>
</xsl:element>
<xsl:if test="$remaining">
<xsl:call-template name="split">
<xsl:with-param name="input" select="$remaining"/>
<xsl:with-param name="name" select="$name"/>
<xsl:with-param name="length" select="$length"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<强>输出强>
<root type="array">
<persons>
<person_id>_:genid1</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is a </oneof>
<oneof>very long </oneof>
<oneof>string</oneof>
</oneofs>
</persons>
<persons>
<person_id>_:genid108</person_id>
<type>http://www.w3.org/2000/01/rdf-schema#Datatype</type>
<oneofs>
<oneof>This is a</oneof>
<oneof>nother ver</oneof>
<oneof>y long str</oneof>
<oneof>ing</oneof>
</oneofs>
</persons>
</root>
看看上面的内容,让我知道什么是没有意义的。