Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Not extracting data correctly Not extracting data correctlyTo: NULL Date: 9/8/2008 4:41:00 PM
The following input xml looks like this:
<ns0:Root xmlns:ns0="http://Schemas.Input">
<Record>
<SubRecord Qualifier="AA">
<Data>Here is AA Data</Data>
</SubRecord>
<SubRecord Qualifier="ZZ">
<Data>Here is ZZ Data</Data>
</SubRecord>
</Record>
</ns0:Root>
I have the following xsl:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0"
xmlns:s0="http://Schemas.Input" xmlns:ns0="http://Schemas.Output"
xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0"
indent="yes" />
<xsl:template match="/">
<xsl:apply-templates select="/s0:Root" />
</xsl:template>
<xsl:template match="/s0:Root">
<ns0:Root>
<Record>
<xsl:for-each select="Record">
<xsl:variable name="var:v1"
select="userCSharp:LogicalEq(string(SubRecord/@Qualifier) , "ZZ")"
/>
<xsl:if test="string($var:v1)='true'">
<xsl:variable name="var:v2" select="SubRecord/Data/text()" />
<Data>
<xsl:value-of select="$var:v2" />
</Data>
</xsl:if>
</xsl:for-each>
</Record>
</ns0:Root>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[
public bool LogicalEq(string val1, string val2)
{
bool ret = false;
double d1 = 0;
double d2 = 0;
if (IsNumeric(val1, ref d1) && IsNumeric(val2, ref d2))
{
ret = d1 == d2;
}
else
{
ret = String.Compare(val1, val2, StringComparison.Ordinal) == 0;
}
return ret;
}
public bool IsNumeric(string val)
{
if (val == null)
{
return false;
}
double d = 0;
return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands
| System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out d);
}
public bool IsNumeric(string val, ref double d)
{
if (val == null)
{
return false;
}
return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands
| System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out d);
}
]]></msxsl:script>
</xsl:stylesheet>
However it does not pull the data (because it is not the first occurence),
how can I get it to span thru all of the subrecords but still drive the
output based on the input record.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
