xml - Dynamic parent headers in XSL? -
i have set of several .xml files processed .csv file using xsltproc.
i've managed find how build dynamic child headers, can same parent ones?
here's i've got far:
xml:
<arrayofvw_retailer_consumer_meter_details_addresses xmlns:i="http://www.w3.org/2001/xmlschema-instance"> <vw_retailer_consumer_meter_details_addresses> <addressline2>sector f-2, mirpur</addressline2> <billingdate>1</billingdate> <blockorpostalstopnumber /> <city>mirpur</city> <consumercontactid>b09a8b6e-84f9-4d15-a62d-4074a7224690</consumercontactid> <consumerid>173410</consumerid> <consumptionaboveaveragelimit>1.30</consumptionaboveaveragelimit> <consumptionbelowaveragelimit>0.700</consumptionbelowaveragelimit> <countryregion>pakistan</countryregion> <excessloadlimit>1.300</excessloadlimit> <exteral_reading_multiplier>1.000</exteral_reading_multiplier> <firstname>abc</firstname> <hasbreakerinstalled>false</hasbreakerinstalled> <interal_reading_multiplier>1.000</interal_reading_multiplier> <isprepaid>false</isprepaid> <lastname i:nil="true" /> <mastermeterid>t10_sha_ham</mastermeterid> <meterid>bhr141400258</meterid> <meter_in_service_end_date i:nil="true" /> <meter_in_service_end_reading i:nil="true" /> <meter_in_service_start_date>2014-08-23t00:00:00</meter_in_service_start_date> <meter_in_service_start_reading>0.000</meter_in_service_start_reading> <middlename i:nil="true" /> <postalcode /> <recid>758b4798-f939-4d91-89a9-a341b9b94b2d</recid> <remarks i:nil="true" /> <salution>mr</salution> <servicelocation>ffda46df-6e49-4e64-a341-002cfed87fa0</servicelocation> <stateprovince>kashmir</stateprovince> <suffix i:nil="true" /> <unitorhousenumber /> </vw_retailer_consumer_meter_details_addresses> </arrayofvw_retailer_consumer_meter_details_addresses>
xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:template match="/*"> <xsl:for-each select="*[1]/*"> <xsl:text>"</xsl:text> <xsl:value-of select="name()" /> <xsl:text>"</xsl:text> <xsl:if test="position() != last()">,</xsl:if> <xsl:if test="position() = last()"> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> <xsl:apply-templates /> </xsl:template> <xsl:template match="/impex"> <xsl:apply-templates select="vw_retailer_consumer_meter_details_addresses[1]" mode="header" /> <xsl:apply-templates select="vw_retailer_consumer_meter_details_addresses" /> </xsl:template> <xsl:template match="*" mode="header"> <xsl:text>"</xsl:text> <xsl:value-of select="$headerval" /> <xsl:text>"</xsl:text> </xsl:template> <xsl:template match="vw_retailer_consumer_meter_details_addresses"> <xsl:apply-templates select="*" /> </xsl:template> <xsl:template match="*"> <xsl:text>"</xsl:text> <xsl:value-of select="." /> <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="position()=last()"> <xsl:text> </xsl:text> </xsl:when> <xsl:otherwise>,</xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
what need change in xsl in order make work if parent header arrayofvw_retailer_consumer_meter_details_addresses
changes else? thank you!
how this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="text" encoding="utf-8" /> <xsl:variable name="q" select="'"'" /> <xsl:variable name="d" select="','" /> <xsl:template match="/*"> <xsl:for-each select="*[1]"> <xsl:apply-templates select="*" mode="header" /> <xsl:text>
</xsl:text> </xsl:for-each> <xsl:for-each select="*"> <xsl:apply-templates select="*" mode="data" /> <xsl:text>
</xsl:text> </xsl:for-each> </xsl:template> <xsl:template match="*" mode="header"> <xsl:if test="position() > 1"><xsl:value-of select="$d" /></xsl:if> <xsl:value-of select="concat($q, name(), $q)" /> </xsl:template> <xsl:template match="*" mode="data"> <xsl:if test="position() > 1"><xsl:value-of select="$d" /></xsl:if> <xsl:value-of select="concat($q, ., $q)" /> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment