M
Mike
Newbie question. I want to traverse an almost arbitrary XML formatted
file and punch its attributes into a list. The list will contain the
following information: Row-index, indent-level, element-name,
attribute-name, attribute value.
I was almost able to do this in two stages. The first XSLT script
punched an intermediate XML file containing row elements that looked
like this:
<Row elementName="Loan" attributeName="Loan_ID"
attributeValue="0123456789"/>
<Row elementName="Borrower" attributeName="Borrower_ID"
attributeValue="555"/>
where Borrower is a sub-element of Loan. The problem is that I can't
figure out how to make XSLT keep an indent count for arbitrary
elements. What I want is an indent count for Loan = "1.0.0" and an
indent count for Borrower = "1.1.0" to indicate that Borrower is (the
1st) sub-element of Loan and that Loan is (the 1st) high level element.
Any clue would be appreciated. BTW, here is my first stage script:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" version="1.0" encoding="UTF-8"/>
<!-- This script takes a Loan Setup XML file as input and generates an
-->
<!-- intermediate XML file as output. The reason for this step is to
-->
<!-- simplify the algorithm needed to produce the final SYLK formatted
-->
<!-- ASCII files that in turn will be used to populate Excel
-->
<!-- spreadsheets.
-->
<xsl:template match="/schema">
<xsl:element name="schema">
<xsl:apply-templates select="LoanFile"/>
</xsl:element>
</xsl:template>
<xsl:template match="LoanFile">
<xsl:element name="LoanFile">
<xsl:apply-templates select="*">
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<!-- For each attribute in the current element generate a Row element
-->
<!-- with new attributes
-->
<xsl:template match="@*">
<xslaram name="elementName"/>
<xsl:variable name="namo"><xsl:value-of
select="name()"/></xsl:variable>
<xsl:element name="Row">
<xsl:attribute name="elementName">
<xsl:value-of select="$elementName"/>
</xsl:attribute>
<xsl:attribute name="attributeName">
<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:attribute name="attributeValue">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:element>
</xsl:template>
<!-- For each input element invoke the elementName template -->
<xsl:template match="*">
<!--Process attributes-->
<xsl:apply-templates select="@*">
<xsl:with-param name="elementName" select="name()"/>
</xsl:apply-templates>
<!--Process child elements-->
<xsl:apply-templates select="*">
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
--Thank you,
--Mike Jr.
file and punch its attributes into a list. The list will contain the
following information: Row-index, indent-level, element-name,
attribute-name, attribute value.
I was almost able to do this in two stages. The first XSLT script
punched an intermediate XML file containing row elements that looked
like this:
<Row elementName="Loan" attributeName="Loan_ID"
attributeValue="0123456789"/>
<Row elementName="Borrower" attributeName="Borrower_ID"
attributeValue="555"/>
where Borrower is a sub-element of Loan. The problem is that I can't
figure out how to make XSLT keep an indent count for arbitrary
elements. What I want is an indent count for Loan = "1.0.0" and an
indent count for Borrower = "1.1.0" to indicate that Borrower is (the
1st) sub-element of Loan and that Loan is (the 1st) high level element.
Any clue would be appreciated. BTW, here is my first stage script:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml" version="1.0" encoding="UTF-8"/>
<!-- This script takes a Loan Setup XML file as input and generates an
-->
<!-- intermediate XML file as output. The reason for this step is to
-->
<!-- simplify the algorithm needed to produce the final SYLK formatted
-->
<!-- ASCII files that in turn will be used to populate Excel
-->
<!-- spreadsheets.
-->
<xsl:template match="/schema">
<xsl:element name="schema">
<xsl:apply-templates select="LoanFile"/>
</xsl:element>
</xsl:template>
<xsl:template match="LoanFile">
<xsl:element name="LoanFile">
<xsl:apply-templates select="*">
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<!-- For each attribute in the current element generate a Row element
-->
<!-- with new attributes
-->
<xsl:template match="@*">
<xslaram name="elementName"/>
<xsl:variable name="namo"><xsl:value-of
select="name()"/></xsl:variable>
<xsl:element name="Row">
<xsl:attribute name="elementName">
<xsl:value-of select="$elementName"/>
</xsl:attribute>
<xsl:attribute name="attributeName">
<xsl:value-of select="name()"/>
</xsl:attribute>
<xsl:attribute name="attributeValue">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:element>
</xsl:template>
<!-- For each input element invoke the elementName template -->
<xsl:template match="*">
<!--Process attributes-->
<xsl:apply-templates select="@*">
<xsl:with-param name="elementName" select="name()"/>
</xsl:apply-templates>
<!--Process child elements-->
<xsl:apply-templates select="*">
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
--Thank you,
--Mike Jr.