I need to process a list of unknown attributes in a node. Normally I would test if the attributes exist and process each one.
Now I have an instance where I know the node but not the attributes and I need to process them. They would be processed in exactly the same way except for the name and value of the attribute.
For example:
With this xml file:
I have the following xslt file:
Here I know what the attributes are and get the following results:
Is there a way to process the attributes the same way without knowing what the attribute names are such that I would have the same resultes for each attribute with only the <tagName> having the name of the attribute and <value> having the value of the attribute?
Thanks,
Tom
Now I have an instance where I know the node but not the attributes and I need to process them. They would be processed in exactly the same way except for the name and value of the attribute.
For example:
With this xml file:
Code:
<RESPONSE MISMOVersionID="2.6">
<REPORT _ID="Major" MajorFormType="Form102">
<FORM _ID="Minor" MinorFormType="Form240">
<IMAGE _ID="Im2"/>
</FORM>
</REPORT>
<METHODS Description="THIS IS SUMMARY">
<COMPARISON ID="241" ComparisonAmount="352,000">
<SALE SequenceId="0" state="true" saleDate="05/15/2011">
<LOCATION Address="9107 Forest Ct" Address2="Franklin, CT"/>
<ADJUSTMENT Type="Concessions" _Description="N/A"/>
</SALE>
</COMPARISON>
</METHODS>
</RESPONSE>
I have the following xslt file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="METHODS/COMPARISON/SALE">
<xsl:with-param name="reportName" select="REPORT/@MajorFormType"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- Now we handle the other sections after the DATA section -->
<xsl:template match="SALE">
<xsl:param name="reportName"/>
<xsl:if test="@state">
<form>
<section>
<xsl:value-of select="../@SequenceId"/>
</section>
<formName>
<xsl:value-of select="$reportName"/>
</formName>
<tagName>
<xsl:text>state</xsl:text>
</tagName>
<value>
<xsl:value-of select="@state"/>
</value>
</form>
</xsl:if>
<xsl:if test="@saleDate">
<form>
<section>
<xsl:value-of select="../@SequenceId"/>
</section>
<formName>
<xsl:value-of select="$reportName"/>
</formName>
<tagName>
<xsl:text>saleDate</xsl:text>
</tagName>
<value>
<xsl:value-of select="@saleDate"/>
</value>
</form>
</xsl:if>
<xsl:apply-templates>
<xsl:with-param name="reportName" select="$reportName"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Here I know what the attributes are and get the following results:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RESPONSE>
<form>
<section></section>
<formName>Form102</formName>
<tagName>state</tagName>
<value>true</value>
</form>
<form>
<section></section>
<formName>Form102</formName>
<tagName>saleDate</tagName>
<value>05/15/2011</value>
</form>
</RESPONSE>
Is there a way to process the attributes the same way without knowing what the attribute names are such that I would have the same resultes for each attribute with only the <tagName> having the name of the attribute and <value> having the value of the attribute?
Thanks,
Tom