xslt help

Saraswathy
2010-10-04
2014-06-25
  • Saraswathy
    Saraswathy
    2010-10-04

    Hi,
    I'm new to xslt

    I have an xml as follows

    <root>
    <agency>hhs.fda.ora.mar</agency>
    <agency>hhs.fda.ora.fms</agency>
    <agency>hhs.fda.ora.oss</agency>
    <agency>hhs.fda.cvm.med</agency>
    <agency>hhs.fda.cvm.care</agency>
    <agency>hhs.fda.cder.de</agency>
    <agency>hhs.fda.ora.fax</agency>
    <agency>hhs.fda.ora.fml</agency>
    <agency>hhs.fda.ora.elex</agency>
    <agency>hhs.fda.cvm.fed</agency>
    <agency>hhs.fda.cber.res</agency>
    <agency>hhs.fda.cder.eval</agency>
    <agency>hud.cp.com.hou</agency>
    <agency>hud.cp.com.law</agency>
    <agency>hud.fhe.com.hou</agency>
    <agency>hud.lpr.com.hou</agency>
    <agency>hud.pih.com.hou</agency>
    <agency>hud.sdbe.com.hou</agency>
    <agency>hud.sdbe.com.law</agency>
    <agency>hhs.nih.nci.cbt</agency>
    <agency>hhs.nih.nci.tms</agency>
    <agency>hhs.nih.nci.tbs</agency>
    <agency>hhs.nih.nci.edrg</agency>
    <agency>hhs.nih.nci.ncs</agency>
    <agency>hhs.nih.nci.edr</agency>

    ...
    ...
    ...
    <root>

    I need an output html display as

    hhs.fda
    hhs.fda.ora.mar
    hhs.fda.ora.fms
    hhs.fda.ora.oss
    <link>show upto 10<link>

    hhs.nih
    hhs.nih.nci.tms
    hhs.nih.nci.tbs
    hhs.nih.nci.edg
    <link>show upto 10<link>

    hud.cp
    hud.cp.com.law
    hud.cp.com.hou
    <link>show upto 10<link>

    hud.sdbe
    hud.sdbe.com.law
    hud.sdbe.com.hou
    <link>show upto 10<link>

    <link> Show all top 20 agencies <link>

    Clicking on show upto 10 link should display upto 10 agenecies under x+.y+

    Clicking on how all top 20 agencies should display upto upto 20 agencies of
    the form x+.y+
    like
    hhs.fda
    hhs.nci
    hud.cp
    hud.sbde

    and so on.

    How do I do that in xslt?

    Thank you for your help

    Saraswathy.

     
  • Michael Kay
    Michael Kay
    2010-10-04

    I'd recommend posting requests for XSLT coding help on xsl-list at
    mulberrytech.com - this list is intended for things specific to the Saxon
    product.

    A general point of advice, though: before asking the question, be sure you
    know exactly what HTML you want to generate - if necessary produce a mock-up
    by hand and ensure it behaves the way you want in the browser.. Don't confuse
    the two separate topics of designing your HTML and designing the XSLT to
    generate it.

    The general technique for grouping into fixed size groups is typically along
    the lines of <xsl:for-each-group select="agency" group-by="position() idiv 10">
    <group><xsl:apply-templates select="current-group()"/></group>

     
  • Saraswathy
    Saraswathy
    2010-10-04

    Thank you Michael. Points taken.

     
  • How can I get the attributes of nested child elements using local-name OR name() using xslt 2.0

    For example, I'm iterating over a loop and have used:

    <xsl:element name="{fn:concat($nodeName, 's')}">
    <xsl:for-each select="./*">
    <xsl:variable name="noname" select="name()"/>
    <xsl:variable name="name" select="local-name()"/>
    csid ###<xsl:value-of select="$name/CustomerSegments/CustomerSegment/@id"/>
    </xsl:element>

    My xml has data like:

    <CustomerSegmentLists>
    <CustomerSegmentList>
    <Id>1730004b-4749-4d39-b257-fc25ca5698ec</Id>
    <CustomerSegment id="0d1e4bf2-0f99-47af-aeae-530063fed37a" core_data_overridden="false" action="noChange">
    <Name>
    <Value locale="en">CSAccountType</Value>
    </Name>
    <CustomerSegmentVersions>
    <CustomerSegmentVersion effective="2014-05-29T00:00:00" expiration="NONE" action="noChange">
    <Segment id="3a2906f3-40b1-483b-84bf-e816f4fe53ee" type="FieldListInstanceField">
    <CustomerSegmentType element_id="51d5cde9-7587-42d8-926b-3b617b888a22">
    <Field name="AccountType" id="5515eda1-e5ab-4f2a-804e-f313f5047189" type="ElementaryField">

    </CustomerSegmentType>
    </Segment>
    </CustomerSegmentVersion>
    </CustomerSegmentVersions>
    </CustomerSegment>
    </CustomerSegmentList>
    <CustomerSegmentLists>

    Can anyone provide some help please, this is something like iterating over a loop using
    <xsl:for-each select="./*">
    then how can I assign the value of an attribute of a specific tag to a variable, say there is a nested child name customerSegment having attribute as id. then how can I get the attribute value using nodeName or local-name in XSLT 2.0. Please help.

     
  • Michael Kay
    Michael Kay
    2014-06-25

    Hilal,

    1. Please don't add a new question to an old thread when the question is quite unrelated to that thread.

    2. You need to check the formatting help for how to enter XML; your code can't be read.

    3. Your question doesn't seem to belong on this forum anyway, because it's not specific to Saxon. For general XSLT coding questions, I would recommend StackOverflow.