Hello,
I am trying to solve following problem:
Today I use identity transform. to filter elements from my original XML file
and create XML output file.
I have created two XSLTs (base.xslt and filter.xslt), where base.xslt does
the identity transformation and filter.xslt defines filtering rules and
templates.
What I basically want is to filter elements of type "sub" and sort them
under one parent node and make selections of type "main" and sort them under
another parent node. One parent node for each category. (see in Filtered XML
how output shoul look like).
My input XML looks like:
[Original XML]
<Documents>
<Document chapter="1" title="title 1" href="file1.xml">
<Article title="1.1" info="sub"/>
<Article title="1.2" info="main"/>
</Document>
<Document chapter="2" title="title 2" href="file2.xml">
<Article title="2.1" info="sub"/>
<Article title="2.2" info="main"/>
</Document>
</Documents>
[Filtered XML SHOULD LOOK LIKE]
<Documents>
<Document name="main">
<Article title="1.2" info="main"/>
<Article title="2.2" info="main"/>
</Document>
<Document name="sub">
<Article title="1.1" info="sub"/>
<Article title="2.1" info="sub"/>
</Document>
</Documents>
[base.xslt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Import filter rules -->
<xsl:include href="filter.xslt"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
[filter.xslt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="Doc[not(@info='main')][not(@info='sub')]"/>
</xsl:stylesheet>
I would like to generate parent nodes groups automatically based on the
filtered elements.
e.g. if elements containing info="main" are filtered, then they should be
grouped under it's own parent node group called "main" (like in the output
example), same with the other filtered element "sub" should have it's own
group.
So, the pseudo should look something like this:
1. filter all elements where attribute info="main"
2. create parent node called "main" for elements where info="main"
3. place elements (Article) of attribute info="main" under parent node
"main"
and so on iterate, untill original, input XML is filtered completely of the
keywords located in filter.xslt
<Document title="main">
<Article title="1.2" info="main"/>
<Article title="2.2" info="main"/>
</Document>
Thank you in advance!
-xrow
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/