Помогите: попытайтесь преобразовать XML, удалив ведущие нули и пробелы ; ниже XSLT не работает для меня:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="xalan://org.apache.commons.lang.StringUtils"
exclude-result-prefixes="str">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="h1">
<h1>
<xsl:variable name="leadingZeroRemoved">
<xsl:call-template name="removeLeadingZero">
<xsl:with-param name="text" select="." />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="leadingSpaceRemoved">
<xsl:call-template name="removeLeadingSpace">
<xsl:with-param name="text" select="$leadingZeroRemoved" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="trailingSpaceRemoved">
<xsl:call-template name="removeTrailingSpace">
<xsl:with-param name="text" select="$leadingSpaceRemoved" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$trailingSpaceRemoved" />
</h1>
</xsl:template>
<xsl:template name="removeLeadingZero">
<xsl:param name="text" />
<xsl:variable name="h1" select="$text" />
<xsl:choose>
<xsl:when test="starts-with($text,'0')">
<xsl:call-template name="removeLeadingZero">
<xsl:with-param name="text"
select="substring-after($text,'0')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="removeLeadingSpace">
<xsl:param name="text" />
<xsl:variable name="h1" select="$text" />
<xsl:choose>
<xsl:when test="starts-with($h1,' ')">
<xsl:call-template name="removeLeadingSpace">
<xsl:with-param name="text" select="substring-after($h1,' ')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$h1" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="removeTrailingSpace">
<xsl:param name="text" />
<xsl:variable name="h1" select="$text" />
<xsl:choose>
<xsl:when test="str:ends-with($h1,' ')">
<xsl:call-template name="removeTrailingSpace">
<xsl:with-param name="text" select="str:substringBeforeLast($h1,' ')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$h1" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Мой сгенерированный ввод и вывод:
$ cat newXMLTEST.FILE
<?xml version="1.0" encoding="UTF-8"?><School>
<Student>
<Id_Numer>0000034</Id_Numer>
<Name> David</Name>
<Tot_Marks>000000100</Tot_Marks>
<Last_YearTot_Marks>000000000</Last_YearTot_Marks>
<Fee_Paid>000043.01</Fee_Paid>
</Student>
</School>
$ cat ne.xml
<?xml version="1.0" encoding="UTF-8"?>
<School>
<Student>
<Id_Numer>0000034</Id_Numer>
<Name> David</Name>
<Tot_Marks>000000100</Tot_Marks>
<Last_YearTot_Marks>000000000</Last_YearTot_Marks>
<Fee_Paid>000043.01</Fee_Paid>
</Student>
</School>
Но то, что я ищу, выглядит примерно так:
<?xml version="1.0" encoding="UTF-8"?>
<School>
<Student>
<Id_Numer>34</Id_Numer>
<Name>David</Name>
<Tot_Marks>100</Tot_Marks>
<Last_YearTot_Marks>0</Last_YearTot_Marks>
<Fee_Paid>43.01</Fee_Paid>
</Student>
</School>
Я новичок в XSLT и Xpath. Я изменил некоторую онлайн-версию XSLT и пробовал с ней. Заранее спасибо.